Problem :
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
What is the largest prime factor of the number 600851475143 ?
Solution :
#include<iostream> using namespace std; #include<conio.h> void checkprime(unsigned long int a) { int flag=1; for(int i=2;i<a;i++) if(a%i==0) flag=0; if(flag==0) cout<<endl<<a<<" is not a prime number"; else cout<<endl<<a<<" is a prime number"; } int main() { unsigned long int num; int tmp,j=0; int arr[25]; cout<<endl<<"Enter any number :"; cin>>num; while(num!=1) { for(int i=2;i<=num;i++) { if(num%i==0) { num=num/i; arr[j++]=i; break; } } } for(int i=0;i<j;i++) { //cout<<" "<<arr[i]; checkprime(arr[i]); } }
No comments:
Post a Comment