- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem3.cpp
More file actions
Latest commit
49 lines (39 loc) · 670 Bytes
/
Copy pathproblem3.cpp
File metadata and controls
49 lines (39 loc) · 670 Bytes
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
#include<iostream>
#include<stdio.h>
#include<math.h>
//Largest prime factor of a number
usingnamespacestd;
boolisPrime(int n)
{
int i;bool p=true;
for(i=2;i<=sqrtf(n);i++)
{
if(n%i==0)
{
//cout<<"Not Prime";
p=false;
return p;
}
}
//cout<<"Prime";
return p;
}
intmain()
{
//accept the number
unsignedlongint n = 600851475143;
//cout<<"Enter the number"<<endl;
//cin>>n;
//calculate the factors
unsignedlongint j=1;
while(j<sqrtf(n))
{
if(isPrime(j)&(n%j==0))
{
cout<<j<<""; //print the factors
}
j++;
}
return0;
}
//Runtime: 0.717 seconds.Can be improved ??