fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. int main()
  5. {
  6. using namespace std ;
  7.  
  8. //initialize some long ass integers
  9. long long primeanswer = 1,p = 1,sqrt_of_i;
  10. //flag for counting a discovery of a factor
  11. int factorcount = 0;
  12. //for loop counts down in twos from an odd number i is number to check
  13. for (long long i=74;i>0; i=i-2)
  14. {
  15. //reset factor count flag to zero
  16. factorcount =0;
  17. //squaring i means that finding a factor of i wont take as long
  18. sqrt_of_i = sqrt(i);
  19. //loop usues p to get numbers fo checking against square of i
  20. for(long long p=1; p<=sqrt_of_i; p++ )
  21. {
  22. //if there is a remainder of 0 when diveded...
  23. if((i%p)==0)
  24. {
  25. //then a factor has been found, the integer is incremented
  26. factorcount++;
  27. //if there is more than two factors the we are not dealing with a prime
  28. if(factorcount>=2)
  29. {
  30. break;
  31. }
  32. }
  33.  
  34. }
  35. //if we found only one factor (1) then we output the prime :D
  36. if(factorcount<=1)
  37. {
  38. primeanswer = i;
  39. cout<<primeanswer<<" ";
  40. }
  41. }
  42.  
  43. }
  44.  
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
2