Digital Square HDU - 4394 (数论)(DFS)
2017-10-16 00:18
549 查看
Given an integer N,you should come up with the minimum nonnegative integer M.M meets the follow condition:
M2mod10x=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
搜索即可
M2mod10x=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
搜索即可
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #define N 50000 #define INF 10000000000 #define mod 19940417 using namespace std; typedef long long ll; ll n; ll ans; void dfs(ll cur,ll now) { if(cur>n) return; ll c=cur*10; for(int i=0;i<10;i++) { ll temp=i*cur+now; if(temp*temp%c==n%c) if(temp*temp%c==n) ans=min(ans,temp); else dfs(c,temp); } } int main() { int t; scanf("%d",&t); while(t--) { scanf("%lld",&n); if(n==0) { printf("0\n"); continue; } ans=INF; dfs(1,0); if(ans==INF) printf("None\n"); else printf("%lld\n",ans); } return 0; }
相关文章推荐
- (dfs) hdu 4394 Digital Square
- hdu 4394 Digital Square(搜索:DFS)
- hdu 4394 - Digital Square (dfs or bfs)
- HDU 4394 Digital Square【搜索】
- hdu 4394 Digital Square 记忆化搜索
- HDU 4394 Digital Square [搜索]
- hdu 4394 Digital Square
- Digital Square(HDU-4394)
- HDU 4394 - Digital Square(BFS+乘法原理)
- HDU-4394 Digital Square BFS搜索
- HDU 4394 Digital Square
- HDU 1518 Square (DFS+剪枝)
- hdu 1518 Square(dfs)
- DFS HDU 1518 Square
- HDU(4394),数论上的BFS
- 数论---HDU 1163 Eddy's digital Roots
- hdu 3826 Squarefree number 数论
- hdu 1518 Square【DFS+剪枝】
- HDU 1518--Square(DFS)
- hdu 1518 Square (DFS)