fork download
  1. #include <iostream>
  2. #include <cstring>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. const int MAX = 1e8;
  8.  
  9. bool is_squarefree[MAX + 1];
  10. long long solve(int lim = MAX)
  11. {
  12. memset(is_squarefree, true, sizeof(is_squarefree[0]) * (lim + 1));
  13.  
  14. long long res = 0;
  15. for (int u = 1; u <= lim; ++u) {
  16. if (is_squarefree[u]) {
  17. for (int p = 2; u * p * p <= lim; ++p) {
  18. is_squarefree[u * p * p] = false;
  19. res += p - 1;
  20. }
  21. }
  22. }
  23.  
  24. return res;
  25. }
  26.  
  27. int main()
  28. {
  29. for (int n = 1; n <= 100; ++n) {
  30. cout << solve(n) << " ";
  31. }
  32. cout << endl;
  33. return 0;
  34.  
  35. for (int n; cin >> n; ) {
  36. cout << solve(n) << endl;
  37. }
  38. return 0;
  39. }
Success #stdin #stdout 0.01s 5272KB
stdin
Standard input is empty
stdout
0 0 0 1 1 1 1 2 4 4 4 5 5 5 5 8 8 10 10 11 11 11 11 12 16 16 18 19 19 19 19 22 22 22 22 27 27 27 27 28 28 28 28 29 31 31 31 34 40 44 44 45 45 47 47 48 48 48 48 49 49 49 51 58 58 58 58 59 59 59 59 64 64 64 68 69 69 69 69 72 80 80 80 81 81 81 81 82 82 84 84 85 85 85 85 88 88 94 96 105