Advertisement
O_Egor

40

May 25th, 2022 (edited)
554
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. #include <map>
  5. using namespace std;
  6.  
  7. int sumOfDigits(int a)
  8. {
  9.     int sum(0);
  10.     while (a)
  11.     {
  12.         sum += a % 10;
  13.         a /= 10;
  14.     }
  15.     return sum;
  16. }
  17.  
  18. int main()
  19. {
  20.     vector<char> prime(31585, true);
  21.     prime[0] = prime[1] = false;
  22.     for (int i = 2; i <= 31584; ++i)
  23.         if (prime[i])
  24.             if (i * 1ll * i <= 31584)
  25.                 for (int j = i * i; j <= 31584; j += i)
  26.                     prime[j] = false;
  27.    
  28.     int ans(0);
  29.     for (int i = 3159; i < 31584 + 1; ++i)
  30.     {
  31.         if (prime[i])
  32.         {
  33.             ans += sumOfDigits(i);
  34.         }
  35.     }
  36.     cout << ans;
  37.     return 0;
  38. }
Advertisement
RAW Paste Data Copied
Advertisement