水题,搞清楚hanoi的定义就好做了。
/* 1329 */
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath> #define MAXN 55 int b[MAXN];
int a[MAXN]; bool isSquare(int x) {
int y = (int) sqrt(x*1.0); return y*y == x;
} void init() {
int i, j, k;
int n = ;
bool flag; memset(b, , sizeof(b));
for (i=; ; ++i) {
flag = true;
for (j=; j<n; ++j) {
if (b[j]== || isSquare(b[j]+i)) {
flag = false;
b[j] = i;
break;
}
}
if (flag) {
a[n] = i-;
b[n++] = i;
if (n > )
break;
}
}
} int main() {
int t, n; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif init();
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
printf("%d\n", a[n]);
} return ;
}