fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int MAXA = 1000000;
  4. vector<bool> isPrime(MAXA + 1, true);
  5. void sieve() {
  6. isPrime[0] = isPrime[1] = false;
  7. for (int i = 2; 1LL * i * i <= MAXA; i++) {
  8. if (isPrime[i]) {
  9. for (int j = i * i; j <= MAXA; j += i) {
  10. isPrime[j] = false;
  11. }
  12. }
  13. }
  14. }
  15. int main() {
  16. ios::sync_with_stdio(false);
  17. cin.tie(nullptr);
  18. sieve();
  19. int n;
  20. cin >> n;
  21. long long ans = 0;
  22. for (int i = 0; i < n; i++) {
  23. for (int j = 0; j < n; j++) {
  24. int x;
  25. cin >> x;
  26. if ((i == j || i + j == n - 1) && isPrime[x]) {
  27. ans++;
  28. }
  29. }
  30. }
  31.  
  32. cout << ans;
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
Standard output is empty