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. Lucene的配置及创建索引全文检索

    Lucene 是一个开放源代码的全文检索引擎工具包,但它不是一个完整的全文检索引擎,而是一个全文检索引擎的架构,提供了完整的查询引擎和索引引擎,部分文本分析引擎(英文与德文两种西方语言).Lucene ...

  2. RPC框架实现思路浅析

    第一部分,设计分析 远程调用要解决的主要问题: 1,序列化 : 如何将对象转化为二进制数据进行传输,如何将二进制数据转化对象 2,数据的传输(协议,第三方框架) 3,服务的注册/发现,单点故障,分布式 ...

  3. window.onerror 应用实例

    详见: http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp75   window.onerror = function(sMessa ...

  4. IOS学习【xcode 7新特性url链接】

    由于xcode7的更新,在访问http链接的时候会输出错误信息 The resource could not be loaded because the App Transport Security ...

  5. 文件系统的几种类型:ext3, s…

    分类: 架构设计与优化 1.  ext3 在异常断电或系统崩溃(不洁关机, unclean system shutdown  ).每个已挂载ext2文件系统计算机必须使用e2fsck程序来检查其一致性 ...

  6. 【★】深入BGP原理和思想【第一部】

    前言:学思科技术我想说,浅尝辄止,不是天才千万别深钻.和我研究高等数学一样,越深入就会发现越多的问题与不合理之处.尤其对于IT界,算法的最终解释权还是掌握在老外手中,所以对于有些细节,我们" ...

  7. 转:【Java并发编程】之十六:深入Java内存模型——happen-before规则及其对DCL的分析(含代码)

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/17348313 happen-before规则介绍 Java语言中有一个"先行发生 ...

  8. 转:【Java并发编程】之十:使用wait/notify/notifyAll实现线程间通信的几点重要说明

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/17225469    在Java中,可以通过配合调用Object对象的wait()方法和no ...

  9. 201521123084 《Java程序设计》第14周学习总结

    1. 本周学习总结 以你喜欢的方式(思维导图.OneNote或其他)归纳总结数据库相关内容. answer: 2. 书面作业 1. MySQL数据库基本操作 1.1 建立数据库test.表studen ...

  10. 个人作业3—个人总结(Alpha阶段)

    一.关于Alpha阶段的总结 1.我们团队的情况 关于我们拖拉机团队,大家在一起做项目的这几周算是比较团结.首先组长布置的任务,每个人都有认真去做,每次例会还会总结不足,提出改进,并且实施这些改进:其 ...