declaring | SoloLearn: Learn to code for FREE!



if(x <= 1977571 && x != 0){ for(int i=2;i<=x;i++){ if(x%i==0){ cout<<x<<" is not prime."; } } if( i == x){ cout<<x<<" is prime!"; } }

5/27/2017 11:25:33 AM


1 Answer

New Answer


you can use following data type for large numbers: long int x; long long int x; and if number is only expected to be positive : unsigned long int x; unsigned long long int x; Hope that helps.Thanks. Suggestion: you can make your loop efficient by checking if the given number is even or not(divisible by 2). If not then run a loop which jumps by two by all odd numbers which makes your code twice efficient then this one. Hope that helps.Thanks.