fork download
  1. /*
  2.   Cred : SunnyYeahBoi
  3.   It's my last chance (⌐■_■)
  4.   Problem :
  5. */
  6.  
  7. #include<bits/stdc++.h>
  8.  
  9. using namespace std;
  10.  
  11. #define int long long
  12. #define double long double
  13. #define endl "\n"
  14. #define NAME "a"
  15.  
  16. const int MAXN = 1e6 + 5;
  17. const int inf = 1e18;
  18. const int MOD = 1e9 + 7;
  19.  
  20. void FileInput(){
  21. if(fopen(NAME".inp" , "r") == NULL)
  22. freopen(NAME".inp" , "w" , stdout);
  23. freopen(NAME".inp" , "r" , stdin);
  24. freopen(NAME".out" , "w" , stdout);
  25. }
  26.  
  27. int n;
  28.  
  29. // cong(a , b) trả về a + b
  30.  
  31. const int LIM = 1e7 + 5;
  32. bool isPrime[LIM];
  33.  
  34. void sieve(){
  35. for(int i = 1 ; i <= LIM ; i++)
  36. isPrime[i] = true;
  37.  
  38. isPrime[0] = false;
  39. isPrime[1] = false;
  40. for(int i = 2 ; i * i <= LIM ; i++){
  41. if(isPrime[i] == true){
  42. for(int j = 2 * i ; j <= LIM ; j += i)
  43. isPrime[j] = false;
  44. }
  45. }
  46. }
  47.  
  48. int tcs(int x){
  49. int res = 0;
  50. while(x > 0){
  51. res += x % 10;
  52. x /= 10;
  53. }
  54. return res;
  55. }
  56.  
  57. void solve(){
  58. sieve();
  59. int l , r;
  60. cin >> l >> r;
  61. for(int i = l ; i <= r ; i++)
  62. if(isPrime[i] && isPrime[tcs(i)])
  63. cout << i << " ";
  64. }
  65.  
  66. int32_t main(){
  67. FileInput();
  68. ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  69. int t = 1;
  70. // cin >> t;
  71. while(t--)
  72. solve();
  73. return 0;
  74. }
  75.  
Success #stdin #stdout 0.06s 13580KB
stdin
Standard input is empty
stdout
Standard output is empty