Why is this c++ program not working?
include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{int n,i=1,k=1,j=0;
cin>>n;
while(i<=n){
if(n%i==0){
while(k<=i){
if(i%k==0)
j++;
k++;}}
if(j==2) cout<<i<<endl;
j=0;
k=1;
i++;
}
system("PAUSE");
return 0;
}
the program should list the prime divisors of n, it works for some numbers however when I tried with 6008514751 for an example it did not work it shows 2,3,7,41,47 can you help me please.and please I'm a beginner so please try to be as simple as possible thank you.
6008514751 is about three times bigger than a typical 32-bit int can hold. Try printing n (cout << n) after reading it, to see what you're actually analyzing.
Switch to unsignedlonglong if you want to handle the numbers that big.