fork download
  1. def is_prime(n):
  2. if n <= 1:
  3. return False
  4. for i in range(2, int(n**0.5) + 1):
  5. if n % i == 0:
  6. return False
  7. return True
  8.  
  9. a = int(input())
  10. lst = list(map(int, input().split()))[:a]
  11. m = int(input())
  12. ans = []
  13.  
  14. for _ in range(m):
  15. l, r = map(int, input().split())
  16. count = 0
  17. for i in lst[l : r + 1]:
  18. temp = i
  19. if is_prime(temp // 10) and is_prime(temp // 100):
  20. for j in range(1, 10):
  21. if is_prime(i * 10 + j):
  22. count += 1
  23. break
  24. else:
  25. pass
  26. ans.append(count)
  27.  
  28. for i in ans:
  29. print(i)
  30.  
Success #stdin #stdout 0.08s 14064KB
stdin
6
59 12 57 53 23 313
3
1 3
2 5
3 6
stdout
0
1
1