求助:欧拉计划第三题!!
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;
}
我的代码半天运行不出结果,请大家看看我的代码有什么问题,有什么可以优化的。谢谢!