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. Django 后台支持中文方法

    今天遇到的一个问题,mark一下: django后台可以支持中文界面,一开始一直纠结于settings.py 中 LANGUAGE_CODE = 'en-us'中的'en-us'该更改成什么.zh-c ...

  2. 我的项目经验总结——CDN镜像:1(初探)

    前言 其实,这个标题有些大,作为一个小白,只是在实际工作中经常听闻我司的CDN服务如何如何牛B……而且我司的云服务还拿到了工信部的CDN牌照……那么,作为一个研发仔,怎么能不去了解和熟悉呢?!不过,这 ...

  3. JavaScript在应用中的技巧(一)

    分享一些在JavaScript中遇到的一些实用的技巧. 理解JavaScript的数值型数据类型 JavaScript的数值型数据类型只有一种:number.即不管是整数还是浮点数,JavaScrip ...

  4. 浏览器控制台console的使用

    前天在团队项目中因为产品需求在提交订单的时候需要多个页面的数据作为提交接口的参数,这种需求让人醉醉的,项目用angular来做的,没办法只能用全局变量来定义要交互的值和localStorage来临时的 ...

  5. WebForm页面间传值方法(转)

    Asp.NET WEB FORMS 给开发者提供了极好的事件驱动开发模式.Asp .NET为我们提供了三种方式,一种是可以通过用QueryString来传送相应的值,再一种是通过session变量来传 ...

  6. Push or Pull?

    采用Pull模型还是Push模型是很多中间件都会面临的一个问题.消息中间件.配置管理中心等都会需要考虑Client和Server之间的交互采用哪种模型: 服务端主动推送数据给客户端? 客户端主动从服务 ...

  7. javascript 学习笔记 -- js获取本地文件信息

    JavaScript是跑在浏览器中,所以对于JavaScript读取本地文件不想c++ 和 java那样easy.网上有很多关于读取本地文件的方法,许多是用ActiveXObject控件.Active ...

  8. 201521123082 《Java程序设计》第7周学习总结

    201521123082 <Java程序设计>第7周学习总结 标签(空格分隔): Java 1. 本周学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. 2. 书面作业 1. ...

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

    1. 本周学习总结 2. 书面作业 Q1.常用异常 题目5-1 1.1 截图你的提交结果(出现学号) 1.2 自己以前编写的代码中经常出现什么异常.需要捕获吗(为什么)?应如何避免? 1.3 什么样的 ...

  10. 201521123019 《Java程序设计》第11周学习总结

    1. 本章学习总结 2. 书面作业 Q1.互斥访问与同步访问 完成题集4-4(互斥访问)与4-5(同步访问) 1.1除了使用synchronized修饰方法实现互斥同步访问,还有什么办法实现互斥同步访 ...