fork download
  1. #include <iostream>
  2. #include <bitset>
  3. using namespace std;
  4. using ll = long long;
  5. bitset<10000005> p;
  6.  
  7. bool ok(ll n) {
  8. if(!p[n]) return 0;
  9. bool dk = 0;
  10. for(int i = 0;i < 10;i++) {
  11. if(p[n * 10 + i]) {
  12. dk = 1;
  13. break;
  14. }
  15. }
  16. if(!dk) return 0;
  17. while(n) {
  18. if(!p[n]) return 0;
  19. n /= 10;
  20. }
  21. return 1;
  22. }
  23. ll n, t, x, l, r;
  24. static ll pre[3000005];
  25. void setup() {
  26. p.set();
  27. p[0] = p[1] = 0;
  28. for(int i = 2;i * i < 10000005;i++){
  29. if(p[i]) {
  30. for(int j = i * i;j < 10000005;j+=i) {
  31. p[j] = 0;
  32. }
  33. }
  34. }
  35. cin >> n >> x;
  36. pre[0] = (ok(x));
  37. for(int i = 1;i < n;i++) {
  38. cin >> x;
  39. pre[i] = pre[i - 1] + ok(x);
  40. }
  41.  
  42. }
  43. void sovle() {
  44. cin >> l >> r;
  45. l--,r--;
  46. if(!l) cout << pre[r] << '\n';
  47. else cout << pre[r] - pre[l - 1] << '\n';
  48. }
  49. int main()
  50. {
  51. ios_base::sync_with_stdio(0);
  52. cin.tie(0);cout.tie(0);
  53. setup();
  54. cin >> t;
  55. while(t--)
  56. sovle();
  57. }
  58.  
Success #stdin #stdout 0.04s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty