You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
761 B
C++

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int N = 15e4 + 40;
int lst[N];
int vis[1044650];
int str[256];
bool isPigeon(int x, int c)
{
while (x > 1)
{
if (vis[x] == c) return false;
vis[x] = c;
int len = 0;
for (; x; x /= 10)
str[len++] = x % 10;
for (int i = 0; i < len; i++)
x += str[i] * str[i];
}
return true;
}
int main()
{
int rs = 0;
for (int i = 1; rs < N; i++)
if (isPigeon(i, i))
lst[rs++] = i;
int Q, k;
scanf("%d", &Q);
while (Q--)
scanf("%d", &k), printf("%d\n", lst[k - 1]);
return 0;
}