1096 Consecutive Factors (20分)

    技术2022-07-10  128

    1096 Consecutive Factors (20分)

    注意:这里寻找连续的乘积上限为2, 下限为根号n,否则测试点4过不了。当找不到一个因子的时候,如n=3的时候就可以直接输出n。

    #include<cstdio> #include<cmath> #include<algorithm> using namespace std; typedef long long LL; int main() { int n, num, maxN = 0; scanf("%d", &n); int sqr = (int)sqrt(1.0*n); for(int i = 2; i <= sqr; i++) { int cnt = 0, m = n, j = i; while(m % j == 0) { cnt++; m /= j; j++; } if(maxN < cnt) { maxN = cnt; num = i; } } if(maxN == 0) printf("1\n%d", n); else { printf("%d\n", maxN); for(int i = num; i < num+ maxN; i++) { printf("%d", i); if(i <num+ maxN-1) printf("*"); } } }
    Processed: 0.009, SQL: 9