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: M2%10x=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 <=109), 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 <iostream>
#include <stdio.h>
#include <set>
#include <string.h>
#include <algorithm>
#include <queue>
using namespace std;
#define ll long long
ll n,nu,ans;
void init()
{
ll nn=n;
nu=;
while(nn)
{
nn/=;
nu*=;
}
}
bool fun()
{
int i,ok=;
ans=n;
ll now,x,y,noww;
queue<pair<ll,ll> >q;
while(!q.empty())
q.pop();
q.push(make_pair(,));
while(!q.empty())
{
x=q.front().first;
now=q.front().second;
noww=now*;
q.pop();
for(i=;i<;i++)
{
y=x+now*i;
if(y*y%nu==n){ans=min(ans,y);ok=;}
else
if(y*y%noww==n%noww)q.push(make_pair(y,noww));
}
}
if(ok)return ;
return ;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
cin>>n;
if(n==)
{
cout<<<<endl;
continue;
}
init();
if(fun())
{
cout<<ans<<endl;
}
else printf("None\n");
}
}
 

Digital Square 搜索的更多相关文章

  1. Digital Square(hdu4394)搜索

    Digital Square Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...

  2. hdu 4394 Digital Square(bfs)

    Digital Square Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  3. HDU 4394 Digital Square

    Digital Square Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  4. HDU 1518 Square 搜索

    Problem Description Given a set of sticks of various lengths, is it possible to join them end-to-end ...

  5. hdu Digital Square(广搜)

    题目:给出n,求出最小的m,满足m^2  % 10^k = n,其中k=0,1,2 http://acm.hdu.edu.cn/showproblem.php?pid=4394 只要有一个x满足条件便 ...

  6. 2012 Multi-University #10

    容斥原理 A Number Sequence 题意:给出n个数,b1,b2,b3……bn,构造n个数,a1,a2,……an(ai>1),使得a1*a2*a3……an=b1*b2……bn 分析:容 ...

  7. Project Euler 80:Square root digital expansion 平方根数字展开

    Square root digital expansion It is well known that if the square root of a natural number is not an ...

  8. ural 1698. Square Country 5(记忆化搜索)

    1698. Square Country 5 Time limit: 2.0 secondMemory limit: 64 MB The first arithmetical operation ta ...

  9. 杭电1518 Square(构成正方形) 搜索

    HDOJ1518 Square Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

随机推荐

  1. 【NOIP2014】子矩阵

    这题如果按暴力做只有一半分,最大时间复杂度为O(C(16,8)*C(16,8)); 很容易算出超时: 我们可以发现如果直接dp会很难想,但是知道选哪几行去dp就很好写状态转移方程: dp[i][j]= ...

  2. java面向对象理解

    面向对象:世间一切事物均可认为是对象,用户不必了解软件内部的实现机制,可根据需要直接调用接口,生成一个正常工作的应用程序. 面向对象的特点:抽象,封装,继承,多态性, 对象:对象就是一个具有明确行为的 ...

  3. C#最佳工具集合:IDE、分析、自动化工具等

    C#是企业中广泛使用的编程语言,特别是那些依赖微软的程序语言.如果您使用C#构建应用程序,则最有可能使用Visual Studio,并且已经寻找了一些扩展来对您的开发进行管理.但是,这个工具列表可能会 ...

  4. c# 读取excel数据的两种方法(转)

    转载自:http://developer.51cto.com/art/201302/380622.htm, 方法一:OleDb: 用这种方法读取Excel速度还是非常的快的,但这种方式读取数据的时候不 ...

  5. 到处是坑的微信公众号支付开发(java)

    之前公司项目开发中支付是用阿里的支付做的,那叫一个简单,随意:悲催的是,现在公司开发了微信公众号,所以我步入了全是坑的微信支付开发中... ------------------------------ ...

  6. jQuery插件——ajax

    一.ajax请求 1.load(url, [data], [callback]) 概述:加载远程的HTML文件代码,并插入到指定的DOM节点中. 参数:url:待装入 HTML 网页网址. data: ...

  7. 必应app测试

    一.app评测 1.个人使用体验 第一次使用必应app看到是微软这么一个大公司做的英语词典,应该会很有名但是我居然没有听说过.当我打开这个软件使用的时候看到界面的视频感觉还不错.但是总感觉这样的app ...

  8. 201521123064 《Java程序设计》第4周学习总结

    1. 本章学习总结 1.1 尝试使用思维导图总结有关继承的知识点. 1.2 使用常规方法总结其他上课内容. ① 以上周PTA实验"形状"为例,Circle类和Rectangle类中 ...

  9. Java 第二周总结

    1.本周学习总结 (1)斐波那契函数 public static int fibonacci(int n)//斐波那契函数 { if(n<=2) { return 1; } else { ret ...

  10. 201521123090《JAVA程序设计》第二周学习总结

    1. 本章学习总结 java基本数据类型 String类对象使用 枚举类型及switch分支 容器的概念 2. 书面作业 Q1.使用Eclipse关联jdk源代码(截图),并查看String对象的源代 ...