/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby,
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <stdio.h>
int max;
int max_num = 0;
int item[100];
int item_seq[100];
int item_res[100];
void f(int last, int depth){
int ix;
for(ix = 10; ix < max_num+1; ix++) {
if (item[ix] != 1) {
if ((last == 0) || (( (last*last) % 10 ) == (ix*ix/100))) {
item[ix] = 1;
item_seq[depth] = ix;
f(ix, depth+1);
item[ix] = 0;
}
}
}
if (depth > max) {
for (ix = 0; ix < 100; ix++) {
item_res[ix] = item_seq[ix]*item_seq[ix];
}
max = depth;
}
}
int main()
{
int ix;
max = 0;
for (ix = 0; ix < 100; ix++) {
item[ix] = 0;
item_seq[ix] = 0;
}
for (ix = 0; ix*ix < 1000; ix++) {
max_num = ix;
}
f(0, 0);
for (ix = 0; ix < max; ix++) {
printf("%d ", item_res[ix]);
}
return 0;
}