#include<stdio.h>
using namespace std;
long square[10001];
int main()
{
long d,i,k,lim,p1,p2,div;
//freopen("in.txt","r",stdin);
for(i=0;i<=10000;i++)
square[i]=i*i;
while(scanf("%ld",&d)==1)
{
switch(d)
{
case 2:
lim=99;
div=10;
break;
case 4:
lim=9999;
div=100;
break;
case 6:
lim=999999;
div=1000;
break;
case 8:
lim=99999999;
div=10000;
break;
}
for(i=0;square[i]<=lim;i++)
{
p1=square[i]/div;
p2=square[i]%div;
k=p1+p2;
cout.width(d);
cout.fill('0');
if(k*k==square[i])
cout<<square[i]<<endl;
}
}
return 0;
}
This comment has been removed by the author.
ReplyDeleteI think, that the switch is unnecesary, yo can do something like this...
ReplyDeletelim=math.pow(10,d)-1;
div=math.pow(10,d-1)
;)
Thanks..
Delete