fork download
  1. #include <bits/stdc++.h> // ZENDA
  2. using namespace std;
  3. #define ll long long
  4. const ll lim=1e6+7;
  5. ll l,r;
  6. vector <ll> a,tmp;
  7. bool snt[lim];
  8. bool check(ll q){
  9. ll tmp=0;
  10. ll w=q;
  11. while (q){
  12. tmp*=10;
  13. tmp+=q%10;
  14. q/=10;
  15. }
  16. if (w==tmp) return 1;
  17. return 0;
  18. }
  19. int main(){
  20. cin.tie(nullptr)->sync_with_stdio(0);
  21. #define F "test"
  22. if (ifstream(F".inp")){
  23. freopen(F".inp","r",stdin);
  24. freopen(F".out","w",stdout);
  25. }
  26. cin>>l>>r;
  27. snt[0]=snt[1]=1;
  28. for (ll i=2;i*i<=lim;i++)
  29. if (!snt[i])
  30. for (ll j=i*i;j<=lim;j+=i)
  31. snt[j]=1;
  32. ll st=sqrt(l)-1;
  33. while (st*st<=r){
  34. if (st*st>=l && st*st<=r)
  35. a.push_back(st);
  36. st++;
  37. }
  38. for (ll v:a)
  39. if (!snt[v]) tmp.push_back(v);
  40. ll res=0;
  41. for (ll v:tmp)
  42. if (check(v)) res++;
  43. cout<<res;
  44. return 0;
  45. }
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty