#include
using namespace std;
const int maxSize = 100 * 1024;
int pnum[maxSize] = { 5, 0, 1, 5, 6, 10 };
int CalcAutomorphicNumbers( int );
int main(int argc, char* argv[]) {
int n;
while(cin >> n) {
cout <
}
return 0;
}
int CalcAutomorphicNumbers(int n) {
if(n<0) return 0;
while(1) {
if(n
int* tmp = lower_bound(&pnum[1], pnum+pnum[0], n);
if(*tmp == n) return tmp-pnum;
return tmp-pnum-1;
}
int tmpNum = pnum[pnum[0]];
int sizeNum = pnum[0];
int i, j;
for(i=1; i<10; i++) {
for(j=1; j
int num1 = tmpNum * i + pnum[j];
int num2 = (num1*num1)%(tmpNum*10);
if(num1 == num2) pnum[pnum[0]++] = num1;
}
}
pnum[pnum[0]] = tmpNum*10;
}
return 0;
}