A wondrous square is an n by n grid which fulfils the following conditions:

It contains integers from 1 to n2 , where each integer appears only once. The sum of integers in any row or column must add up to 0.5xnx(n2+1).

For example the following grid is a wondrous square where the sum of each row or column is 65 when n=5.

```
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 2 19 21 3
11 18 25 2 9
```

Write a program to read n (2<=n<=10) and the values stored in these n by n cells and output if the grid represents a wondrous square or not.

Also output all the prime numbers in the grid along with their row index and column index as shown in the output.The first element of the given grid i.e. 17 is stored at row index 0 and column index 0 and the next element in the row i.e. 24 is stored at row index 0 and column index 1.

Test your program for the following data and some random data.

**SAMPLE DATA:**

```
INPUT:
N = 4
16 15 1 2
6 4 10 14
9 8 12 5
3 7 11 13
OUTPUT: YES IT REPRESENTS A WONDROUS SQUARE.
PRIME ROW INDEX COLUMN INDEX
2 0 3
3 3 0
5 2 3
7 3 1
11 3 2
13 3 3
```

### Have something to say? Log in to comment on this post.

0 comments