1096. Consecutive Factors (20)

秒速五厘米 2022-05-28 05:59 219阅读 0赞

Among all the factors of a positive integer N, there may exist several consecutive numbers. For example, 630 can be factored as 3*5*6*7, where 5, 6, and 7 are the three consecutive numbers. Now given any positive N, you are supposed to find the maximum number of consecutive factors, and list the smallest sequence of the consecutive factors.

Input Specification:

Each input file contains one test case, which gives the integer N (1<N<231).

Output Specification:

For each test case, print in the first line the maximum number of consecutive factors. Then in the second line, print the smallest sequence of the consecutive factors in the format “factor[1]*factor[2]*…*factor[k]“, where the factors are listed in increasing order, and 1 is NOT included.

Sample Input:

  1. 630

Sample Output:

  1. 3
  2. 5*6*7

题目大意:

代码:

  1. #include<stdio.h>
  2. #include<math.h>
  3. int main()
  4. {
  5. int i,j,n,m,k,t,l;
  6. scanf("%d",&n);
  7. for(i=12;i>=1;i--)
  8. {
  9. for(j=2;j<=sqrt(n);j++)
  10. {
  11. long long num=1;
  12. for(l=j;l-j<i;l++)
  13. {
  14. num*=l;
  15. }
  16. if(n%num==0)
  17. {
  18. printf("%d\n",i);
  19. for(k=j;k<l;k++)
  20. {
  21. if(k==j)
  22. {
  23. printf("%d",k);
  24. }
  25. else
  26. {
  27. printf("*%d",k);
  28. }
  29. }
  30. return 0;
  31. }
  32. }
  33. }
  34. printf("1\n%d",n);
  35. return 0;
  36. }

发表评论

表情:
评论列表 (有 0 条评论,219人围观)

还没有评论,来说两句吧...

相关阅读

    相关 1096 大美数

    若正整数 N 可以整除它的 4 个不同正因数之和,则称这样的正整数为“大美数”。本题就要求你判断任一给定的正整数是否是“大美数”。 输入格式: 输入在第一行中给出正整数

    相关 1096B - Substring Removal

    题意:给了长度为n的字符,删除其中的字符,让剩下的字符一样,就满足条件,输出有多少种删法,全部删除,留一个字符也满足条件。 题解:先统计前面连续相同的字符个数,再统计后面连续