fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define fi first
  4. #define se second
  5. #define fo(i,d,c) for(int i=d;i<=c;i++)
  6. #define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  7.  
  8. using namespace std;
  9.  
  10. int n,t;
  11. const int N=1e6;
  12. int cs[10]={0,1,3,7,9};
  13. int a[N+1],f[N+1];
  14.  
  15. bool ktra(int n){
  16. if(n<2) return false;
  17. fo(i,2,sqrt(n)){
  18. if(n%i==0) return false;
  19. }
  20. return true;
  21. }
  22. bool check(int n)
  23. {
  24. if(ktra(n)){
  25. bool ac=true;
  26. fo(i,1,4){
  27. int tmp=n*10+cs[i];
  28. if(ktra(tmp)){
  29. ac=false;
  30. }
  31. }
  32. if(ac){
  33. return false;
  34. }
  35. else{
  36. while(n>10){
  37. n/=10;
  38. if(!ktra(n)){
  39. return false;
  40. }
  41. }
  42. return true;
  43. }
  44. }
  45. else{
  46. return false;
  47. }
  48. }
  49. int main()
  50. {
  51. IOS;
  52. cin>>n;
  53. fo(i,1,n) cin>>a[i];
  54. cin>>t;
  55. f[0]=0;
  56. fo(i,1,n){
  57. f[i]=f[i-1];
  58. if(check(a[i])){
  59. f[i]+=1;
  60. }
  61. }
  62. int u,v;
  63. while(t-->0){
  64. cin>>u>>v;
  65. cout<<f[v]-f[u-1]<<'\n';
  66. }
  67. return 0;
  68. }
  69.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty