fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4.  
  5. void sieve(int ubound, int primes[]);
  6.  
  7. int main()
  8. {
  9. long long n;
  10. int i;
  11. std::cout << "Input Number: ";
  12. std::cin >> n;
  13. if (n < 2){
  14. return 1;
  15. }
  16. long long upperbound = n;
  17. std::vector<int> A(upperbound);
  18. int SquareRoot = sqrt(upperbound);
  19. sieve(upperbound, A.data());
  20. for (i = 0; i < upperbound; i++)
  21. {
  22. if (A[i] == 1 && upperbound%i == 0)
  23. {
  24. std::cout << " " << i << " ";
  25. }
  26. }
  27. return 0;
  28. }
  29.  
  30. void sieve(int ubound, int primes[])
  31. {
  32. long long i, j, m;
  33. for (i = 0; i < ubound; i++)
  34. {
  35. primes[i] = 1;
  36.  
  37. }
  38. primes[0] = 0, primes[1] = 0;
  39. for (i = 2; i < ubound; i++)
  40. {
  41. for (j = i*i; j < ubound; j += i)
  42. {
  43. primes[j] = 0;
  44. }
  45. }
  46. }
  47.  
Success #stdin #stdout 0.21s 3460KB
stdin
2000000
stdout
Input Number:  2  5