Largest Prime Factors
Prime Factors in C
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
Output is 6857
--------------------------------
#include
int main()
{
long long count=2,b=2,x=600851475143,c=0,prime=0;
while(count<x)
{
if(x%count==0)
{c=count;
b=2
while(b<=c)
{if(c%b!=0)
{b++;}
else
{b+=c;}
if(b==c)
{prime=c;
printf("prime: %d\n",prime);
}
count++;}
else
count++;
}
printf("The largest prime factor of %d is: \n%d\n",x,prime);
return 0;
}
No comments:
Post a Comment