求助:欧拉计划第三题!!
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;
}
我的代码半天运行不出结果,请大家看看我的代码有什么问题,有什么可以优化的。谢谢!
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;
}
我的代码半天运行不出结果,请大家看看我的代码有什么问题,有什么可以优化的。谢谢!
...全文
相关推荐
欧拉计划1-50题
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.
详解欧拉计划第622题:完美洗牌
欧拉计划第622题:完美洗牌有这样一种洗牌:将牌张平分为两份,左手拿上半部分牌张,右手拿下半部分牌张,然后,将右手的牌严格地交叉到左手的牌张中,也就是右手的第1张牌处于左手的第1张牌后面,右手的第2张牌处于左手的第2张牌后面,依次类推。......
欧拉计划1-20题中文
1. 10以下的自然数中,属于3和5的倍数的有3,5,6和9,它们之和是23。找出1000以下的自然数中,属于3和5的倍数的数字之和。
ProjectEuler:我的欧拉计划答案
欧拉计划 我的欧拉计划答案
欧拉计划题目50题
欧拉计划经典题目,用于练习,一共60题。欧拉计划经典题目,用于练习,一共60题


