标签:dfs
3 3 21 25
None 11 5
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
#define ll long long
#define CL(a) memset(a,0,sizeof(a))
ll n,k,ans;
ll dfs(ll pe, ll re)//pe表示当前最高位,re表示之前满足条件的数
{
if (pe > n) return 0;
for (int i=0; i<10; i++)
{
ll a = i*pe+re;//最高位10种情况一次搜索
ll aa = a*a%(pe*10);
ll nn = n%(pe*10);
if (aa == nn)
{
if (aa == n)
ans = min(ans, a);
else
dfs(pe*10, a);//往上继续搜索
}
}
return 0;
}
int main()
{
int T;
cin>>T;
while (T--)
{
cin>>n;
ans = INF;
dfs(1, 0);//搜索只搜了1~999999999
if (n==0)
{
cout<<"0"<<endl;
continue;
}
if (n==1000000000)
{
cout<<"None"<<endl;
continue;
}
if (ans!=INF)
cout<<ans<<endl;
else
cout<<"None"<<endl;
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:dfs
原文地址:http://blog.csdn.net/d_x_d/article/details/49179697