You can find quality tech news,tricks,study materials etc contact me:facebook.com/ashwin.sunilkumar
Support Me...........
Please support me by giving donation
contact: aswinavofficial@gmail.com
Total Pageviews
Monday, September 1, 2014
C++ program to find largest prime factor of a number(14 digits supported)
/* largest prime factor */
#include
#include
using namespace std;
bool isPrime(long n, long i);
int main() {
long long n;
long s = (long) sqrt(n);
cout << "/nEnter number which you want to find largest prime factor(upto 14 digits)" << endl;
cin>>n;
for (long i=s; i>1; i--) {
if (n%i==0) {
if(!isPrime(i, 2))
continue;
cout << "Ans: " << i;
break;
}
}
return 0;
}
bool isPrime(long n, long i) {
if (i>=n) {
return true;
} else if (n%i==0) {
return false;
} else {
return isPrime(n, ++i);
}
}
// aiuto
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment