fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int N = 1e7 + 67;
  4. bool d[N];
  5. bool check(long long n) {
  6. long long sum = 0;
  7. long long temp = n;
  8. while (temp > 0) {
  9. sum += temp % 10;
  10. temp /= 10;
  11. }
  12. return d[sum];
  13. }
  14. int main() {
  15. ios_base::sync_with_stdio(0);
  16. cin.tie(0);
  17. fill(d, d + N, true);
  18. d[0] = d[1] = false;
  19. for(int i = 2; i * i < N; i++) {
  20. if(d[i]) {
  21. for(int j = i * i; j < N; j += i) {
  22. d[j] =false;
  23. }
  24. }
  25. }
  26. long long l, r;
  27. if(cin >> l >> r) {
  28. int cnt = 0;
  29. for(long long i = l; i <= r; i++) {
  30. if(d[i] == true && check(i)) {
  31. if(cnt> 0)
  32. cout << " ";
  33. cout << i;
  34. cnt++;
  35. }
  36. }
  37. cout << "\n";
  38. }
  39. }
  40.  
Success #stdin #stdout 0.06s 10228KB
stdin
Standard input is empty
stdout
Standard output is empty