TimeLimit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K(Java/Other)
Problem Description
Square number isvery popular in ACM/ICPC. Now here is a problem about square number again.
Let's consider such a kind of number called K-Omitted-Square-Number(K-OSN). Nis a K-OSN if:
(1) It is a square number.
(2) Its last digit is not 0.
(3) It's not less than 10^K.
(4) If its last K digits are omitted, it's still a square number.
Now, given an even number K, you have to find the largest K-OSN.
Input
There are multipletest cases in this problem.
The first line will contain a single positive integer T(T<=20) indicatingthe number of test cases. Each test case will be a single line containing aneven number K(2<=K<=200).
Output
For each testcase, print a single line containing the largest K-OSN. In case that it will bevery large, you just need to print the number module 2009. If there are noK-OSN, or if the largest K-OSN doesn't exist, print "Oops!"(withoutquotes).
Sample Input
1
4
Sample Output
197
标程:
#include<stdio.h>
const int MAXK=200; //最大的K
const int MODNUM=2009; //用于取模的数
int main()
{
int tn,i; //tn为数据组数
int k,ans; //题目输入的K
int digit[MAXK+10],dn; //用于存放答案的数组和数组的长度
scanf("%d",&tn);
while(tn--)
{
scanf("%d",&k);
dn=0; digit[++dn]=4; //根据规律来构造答案
for(i=1;i<k/2;i++) digit[++dn]=9;
for(i=1;i<k/2;i++) digit[++dn]=0;
digit[++dn]=1;
for(ans=0,i=1;i<=dn;i++) ans=(ans*10+digit[i])%MODNUM;
ans=(ans*ans)%MODNUM;
printf("%d\n",ans);
}
return 0;
}