/ 科创班 /

记录详情

Compile Error

/in/foo.cc:4:12: error: 'n' was not declared in this scope
 int factor(n)
            ^
/in/foo.cc: In function 'int main()':
/in/foo.cc:19:21: error: 'factor' cannot be used as a function
         j = factor(i);
                     ^
/in/foo.cc:24:25: error: 'factor' cannot be used as a function
             j = factor(k);
                         ^

代码

#include <stdio.h>
#include <math.h>

int factor(n)
{
    int i, j = (int)sqrt(n);
    if (n % 2 == 0) return 2;
    for (i = 3; i <= j; i++)
        if (n % i == 0) return i;
    return n;
}

int main()
{
    int i, j, k, m, n;
    scanf("%d%d", &m, &n);
    for (i = m; i <= n; i++)
    {
        j = factor(i);
        k = i / j;
        printf("%d=%d", i, j);
        while (k > 1)
        {
            j = factor(k);
            k /= j;
            printf("*%d", j);
        }
        printf("\n");
    }
    return 0;
}

信息

递交者
类型
递交
题目
分解质因数
题目数据
下载
语言
C++
递交时间
2018-10-17 21:51:20
评测时间
2018-10-17 21:51:20
评测机
分数
0
总耗时
0ms
峰值内存
0 Bytes