## 10087 - The Tajmahal of ++Y2k

Moderator: Board moderators

hesper
New poster
Posts: 2
Joined: Sat Nov 23, 2002 9:08 am

### 10087 - The Tajmahal of ++Y2k

Please, I've just tried to submit 10087 for several times, and ---- WA. I'm afraid I didn't understand the problem well, for:
1. Whether negative and 0 are allowed to construct the magic square?
2. Are there any special test numbers I didn't consider well?

I have two functions to construct the square, and they are certainly right. The following is my main():

[cpp]
int n, sum;
while(fin>>n>>sum)
{
int magic_const = n*(n*n+1)/2;
if( (sum - magic_const)%n == 0 && sum - magic_const >= 0 )
{
int add = (sum - magic_const)/n;
int *p=new int[n*n];
if(n%2 != 0)
oddArray(p, n);
else
evenArray(p, n);
for(int i=0; i<n*n; ++i)
output(p, n, fout);
delete[] p;
}
else
fout<<"You can't be like Shahjahan!\n\n";
}[/cpp]

Whinii F.
Experienced poster
Posts: 151
Joined: Wed Aug 21, 2002 12:07 am
Location: Seoul, Korea
Contact:
Did you check out cases when n == 2 ?
In that case there is no configuration.

edit) Configurations can have 0 or negative integers.
JongMan @ Yonsei

rieo
New poster
Posts: 9
Joined: Tue Jul 04, 2006 10:46 am
Location: Taiwain
i try to solve this problem but get WA, i use formula to get the magic array for 3 types: odd, 4n, 4n+2 and seems good..

is there any critical input i lose?

L=2 print can't

L and S can only use %d?

and every element i printed use %10d ?