求助:欧拉计划第三题!!

hh4062703 hh4062703 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?

我的代码:
#include <stdio.h>
#define MAX 600851475143

int maxfactor (long long int);


int main (void)
{


printf("The bigest factor of max is:%d\n", maxfactor(MAX));

return 0;
}

int maxfactor (long long int n)
{
int factor = 2;

while (n > 1)
{

if (n % factor == 0)
{
n /= factor;

while(n % factor == 0)
{
n /= factor;
}
}
factor += (factor = 2?1:2);
if (factor * factor > n)
break;

}
return factor;
}


我的代码半天运行不出结果,请大家看看我的代码有什么问题,有什么可以优化的。谢谢!
...全文
评论 5
收藏 已收藏
分享
返回顶部
hh4062703
C语言 70,039 成员 243,237 内容