fork download
  1. #include<bits/stdc++.h>
  2. #define For(i,a,b) for(int i=a;i<=b;i++)
  3. #define Ford(i,a,b) for(int i=a;i>=b;i--)
  4. #define ii pair<int,int>
  5. #define sc second
  6. #define fs first
  7. #define N 1000005
  8. #define ll long long
  9. using namespace std;
  10. bool p[N];
  11. ll s1[N], s2[N];
  12. int n;
  13. void sieve()
  14. {
  15. p[0] = p[1] = 1;
  16. int mx = 1e6;
  17. For (i, 2, sqrt(mx))
  18. if (!p[i])
  19. for(int j = i * i; j <= mx;j += i)
  20. p[j] = 1;
  21. }
  22. string str(int n)
  23. {
  24. stringstream s;
  25. s<<n;
  26. return s.str();
  27. }
  28. int val(string s)
  29. {
  30. int n;
  31. stringstream (s)>>n;
  32. return n;
  33. }
  34. int dns(int n)
  35. {
  36. string s=str(n);
  37. reverse(s.begin(),s.end());
  38. return val(s);
  39. }
  40. int main()
  41. {
  42. ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
  43. //freopen("twins.inp", "r", stdin);
  44. //freopen("twins.out", "w", stdout);
  45. sieve();
  46. For(i, 1, 1e6)
  47. {
  48. s1[i] = s1[i-1] + (p[i] ? 0 : i);
  49. s2[i] = s2[i-1] + (!p[i] && !p[dns(i)] && i!=dns(i) ? 1 : 0);
  50. }
  51. cin>>n;
  52. For(i,1,n){
  53. int l, r;
  54. cin >> l >> r;
  55. cout << s1[r] - s1[l-1] << ' ' << s2[r] - s2[l-1] <<'\n';
  56. }
  57. return 0;
  58. }
Success #stdin #stdout 0.11s 20116KB
stdin
Standard input is empty
stdout
Standard output is empty