Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- using namespace std;
- bool isPrime(int n) {
- for (int i = 2; i <= sqrt(n); i++) {
- if (n % i == 0) {
- return false;
- }
- }
- return true;
- }
- int main() {
- int n;
- cin >> n;
- vector<vector<int>> numbers(n, vector<int>(n));
- for (int r = 0; r < n; r++) {
- for (int c = 0; c < n; c++) {
- cin >> numbers[r][c];
- }
- }
- int startCol = 1, finalCol = n - 1, sum = 0;
- for (int r = n - 1; r > n / 2; r--) {
- for (int c = startCol; c < finalCol; c++) {
- if (isPrime(numbers[r][c])) {
- sum += numbers[r][c];
- }
- }
- startCol++;
- finalCol--;
- }
- cout << sum << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement