Digital Square 搜索

Digital Square
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit  Status

Description

Given an integer N,you should come up with the minimum  nonnegative integer M.M meets the follow condition: M 2%10 x=N (x=0,1,2,3....)
 

Input

The first line has an integer T( T< = 1000), the number of test cases. 
For each case, each line contains one integer N(0<= N <=10 9), indicating the given number.
 

Output

For each case output the answer if it exists, otherwise print “None”.
 

Sample Input

3
3
21
25
 

Sample Output

None
11
5
 
 
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <set>
 4 #include <string.h>
 5 #include <algorithm>
 6 #include <queue>
 7 using namespace std;
 8 #define ll long long
 9 ll n,nu,ans;
10 void init()
11 {
12     ll nn=n;
13     nu=1;
14     while(nn)
15     {
16         nn/=10;
17         nu*=10;
18     }
19 }
20 bool fun()
21 {
22     int i,ok=0;
23     ans=n;
24     ll now,x,y,noww;
25     queue<pair<ll,ll> >q;
26     while(!q.empty())
27     q.pop();
28     q.push(make_pair(0,1));
29     while(!q.empty())
30     {
31         x=q.front().first;
32         now=q.front().second;
33         noww=now*10;
34         q.pop();
35         for(i=0;i<10;i++)
36         {
37             y=x+now*i;
38             if(y*y%nu==n){ans=min(ans,y);ok=1;}
39             else
40             if(y*y%noww==n%noww)q.push(make_pair(y,noww));
41         }
42     }
43     if(ok)return 1;
44     return 0;
45 }
46 int main()
47 {
48     int t;
49     scanf("%d",&t);
50     while(t--)
51     {
52         cin>>n;
53         if(n==0)
54         {
55             cout<<10<<endl;
56             continue;
57         }
58         init();
59         if(fun())
60         {
61             cout<<ans<<endl;
62         }
63         else printf("None\n");
64     }
65 }
View Code

 

 

转载于:https://www.cnblogs.com/ERKE/p/3843998.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值