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. 为Ext添加下拉框和日期组件

    Ext.onReady(function(){ var config = { fields:['module'], data:[['新建'],['删除'],['增加']}; var store = n ...

  2. 运用jQuery写的验证表单

    //运用jQuery写的验证表单 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "h ...

  3. GreenOpenPaint简介

    一.项目概述 类似Windows系统下面的画图程序,但是已经从底层全部重新实现,改造成为"图像处理"类程序的基本运行框架. 由于是demo界面,较为简陋,但是因为框架已经搭建完善, ...

  4. MongoDB学习之——安装

    MongoDB安装 说明: 本次安装教程: 版本:mongoDB-3.2.4 安装环境:windows 10 ,64位操作系统 准备:安装包.Robomongo(客户端用于查看mongoDB里面的数据 ...

  5. Porita详解----Items

    Items(项目) 一个item是指从目标网站上爬取的一条单独的数据.例如从京东网站上爬取的一款小米6手机的信息.大家应该对 item (项目)和 item definition(项目定义)做一个区分 ...

  6. [ASP.NET MVC]笔记(二) 数据注解和验证

    验证注解的使用 1.Required:必须字段 [Required] public string FirstName() { get; set; } 2.StringLength:长度限制,或是可选项 ...

  7. UCOS-II学习记录

    本文主要记录使用UCOS II的相关内容.包括如何完成第一个UCOS II应用程序,和如何创建任务,如何获取系统时间,和利用i3086 驱动完成时间获取,屏幕显示,按键驱动,信号量等内容. UCOS- ...

  8. error: The requested URL returned error: 401 Unauthorized while accessing

    我遇到的其中一个问题. 问题描述: 在git push -u origin master是,提示“error: The requested URL returned error: 401 Unauth ...

  9. idea 给maven项目添加依赖(二)

    这里接着上一篇来 我们观察目录发现有两个pom.xml(project object module) 项目是里面的,所以外面的先不管它. 点击里面的pom.xml 1.在<url>节点下面 ...

  10. make: Nothing to be done for 'all' 解决方法

    make: Nothing to be done for 'all' 解决方法 1.这句提示是说明你已经编译好了,而且没有对代码进行任何改动. 若想重新编译,可以先删除以前编译产生的目标文件:make ...