文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Project Euler Problem 3

Project Euler Problem 3

时间:2011-03-10  来源:Ray Z

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

 1 #include <iostream>
 2 using namespace std;
 3 
 4 long long GetFirstFactor(long long num)
 5 {
 6     long long root = sqrt((long double)num);
 7     for(long long i=2; i<root; i++)
 8     {
 9         if(num % i == 0)
10         {
11             return i;
12         }
13     }
14 
15     return num;
16 }
17 
18 int main()
19 {
20     long long num = 600851475143;
21     long factor = 1;
22     while(num > 1)
23     {
24         long f = GetFirstFactor(num);
25         if(f > factor)
26         {
27             factor = f;
28         }
29 
30         num = num / f;
31     }
32 
33     cout << factor << endl;
34     cin.get();
35 }
相关阅读 更多 +
排行榜 更多 +
别惹神枪手安卓版

别惹神枪手安卓版

冒险解谜 下载
坦克战争世界

坦克战争世界

模拟经营 下载
丛林反击战

丛林反击战

飞行射击 下载