c语言编程练习题:7-84 连续因子
作者:yunjinqi   类别:    日期:2023-05-31 10:01:58    阅读:453 次   消耗积分:0 分    

image.png

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

int main()
{
	int N;
	int maxString = 0;
	int count = 0;
	int num = 0;
	int firstNum = 0;
	
	if (scanf("%d",&N)!=EOF){
        int i;
        for(i = 2; i <= sqrt(N); i++)
        {
            num = N;
            count = 0;
            int j = i;
            while(num%j == 0)
            {
                num = num/j;
                j++;
                count++;
            }
            
            if(count > maxString)
            {
                maxString = count;
                firstNum = i;
            }
        }
        
        if(maxString)
        {
            //判断是否存在连续数 
            printf("%d\n",maxString);
            int i;
            for(i = 0; i < maxString; i++)
            {
                printf("%d",firstNum + i);
                if(i != maxString-1)
                {
                    printf("*");
            }
                }
                    
        }
        else
        {
            printf("1\n%d",N);
        }
    }else{
        printf("input wrong");
    }
	return 0;

}


版权所有,转载本站文章请注明出处:云子量化, http://www.woniunote.com/article/209
上一篇:c语言编程练习题:7-83 币值转换
下一篇:c语言编程练习题:7-85 温度转换