-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp3.cpp
57 lines (51 loc) · 923 Bytes
/
p3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
*/
#include<iostream>
#include<vector>
using namespace std;
bool checkprime(long n);
int main()
{
long i,max=1;
const long n=600851475143;
bool flag;
for(i=1;i<=n;i++)
{
if(n%i==0)
{
flag=checkprime(i);
if(flag==true)
{
if(i>max)
{
max=i;
cout<<max<<endl;
}
}
}
}
cout<<"final="<<max<<endl;
return 0;
}
bool checkprime(long n)
{
int flag=1;
for(long i=2;i<n;i++)
{
if(n%i==0)
{
flag=0;
break;
}
}
if(flag==0)
{
return false;
}
else
{
return true;
}
}