fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. const int M = 1000067;
  7. bool pie[M];
  8.  
  9. void sito() {
  10. for (int i = 2; i < M-1; i++) {
  11. pie[i] = true;
  12. }
  13. pie[0] = pie[1] = false;
  14. for (int p = 2; p * p < M; p++) {
  15. if (pie[p]!=0) {
  16. for (int i = p * p; i < M; i += p) {
  17. pie[i] = false;
  18. }
  19. }
  20. }
  21. }
  22.  
  23. int main() {
  24. ios_base::sync_with_stdio(0);
  25. cin.tie(0);
  26.  
  27. sito();
  28.  
  29. long int n;
  30. cin>>n;
  31.  
  32. long long l2 = 0;
  33. long long war = 0;
  34.  
  35. for (int i = 0; i < n; i++) {
  36. int a;
  37. cin >> a;
  38. if (a == 2)
  39. l2++;
  40. else if (pie[a + 2]==1)
  41. war++;
  42.  
  43. }
  44.  
  45. cout << l2 * war << "\n";
  46.  
  47. return 0;
  48. }
Success #stdin #stdout 0.01s 5304KB
stdin
5
2 5 2 13 11
stdout
4