Given a number x, ask positive integer y≥2y≥2, that satisfy the following conditions: 
1. The absolute value of y - x is minimal 
2. To prime factors decomposition of Y, every element factor appears two times exactly.

InputThe first line of input is an integer T ( 1≤T≤501≤T≤50) 
For each test case,the single line contains, an integer x ( 1≤x≤10181≤x≤1018)OutputFor each testcase print the absolute value of y - xSample Input

5
1112
4290
8716
9957
9095

Sample Output

23
65
67
244
70 y是完全平方数,枚举根号y即可,注意左右两边的最小值取小的那个
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<fstream>
#include<set>
#include<memory>
#include<bitset>
#include<string>
#include<functional>
using namespace std; typedef long long LL;
#define INF 0x9f9f9f9f
LL T, n;
bool check(LL t)
{
for (LL i = ; i*i <= t; i++)
{
LL cnt = ;
while (t%i == )
cnt++, t /= i;
if (cnt > ) return false;
}
return true;
}
int main()
{
std::ios::sync_with_stdio(false);
cin >> T;
while (T--)
{
cin >> n;
if (n <= )
{
cout << - n << endl;
continue;
}
LL dis = , tmp = sqrt(n), ans;
while ()
{
LL a = tmp - dis;
if (a*a < n && check(a))
{
ans = n - a * a;
break;
}
dis++;
}
dis = ;
while ()
{
LL a = tmp + dis;
if (a*a >= n && check(a))
{
ans = min(ans, (a*a - n));
break;
}
dis++;
}
cout << ans << endl;
}
}

abs 暴力的更多相关文章

  1. hdu-5778 abs(暴力枚举)

    题目链接: abs Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 131072/131072 K (Java/Others) Pro ...

  2. BestCoder Round #85 hdu5778 abs(素数筛+暴力)

    abs 题意: 问题描述 给定一个数x,求正整数y,使得满足以下条件: 1.y-x的绝对值最小 2.y的质因数分解式中每个质因数均恰好出现2次. 输入描述 第一行输入一个整数T 每组数据有一行,一个整 ...

  3. HDU 5778 abs (素数,暴力)

    题意:给定一个数x,求正整数y≥2y\geq 2y≥2,使得满足以下条件: 1.y-x的绝对值最小 2.y的质因数分解式中每个质因数均恰好出现2次. 析:由于y质因数分解式中每个质因数均出现2次,那么 ...

  4. HDU 5778 abs (暴力枚举)

    abs Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem De ...

  5. HDU 5778 abs (BestCoder Round #85 C)素数筛+暴力

    分析:y是一个无平方因子数的平方,所以可以从sqrt(x)向上向下枚举找到第一个无平方因子比较大小 大家可能觉得这样找过去暴力,但实际上无平方因子的分布式非常密集的,相关题目,可以参考 CDOJ:无平 ...

  6. 1250 Super Fast Fourier Transform(湘潭邀请赛 暴力 思维)

    湘潭邀请赛的一题,名字叫"超级FFT"最终暴力就行,还是思维不够灵活,要吸取教训. 由于每组数据总量只有1e5这个级别,和不超过1e6,故先预处理再暴力即可. #include&l ...

  7. 【BZOJ-4127】Abs 树链剖分 + 线段树 (有趣的姿势)

    4127: Abs Time Limit: 40 Sec  Memory Limit: 256 MBSubmit: 381  Solved: 132[Submit][Status][Discuss] ...

  8. BZOJ4127: Abs

    Description 给定一棵树,设计数据结构支持以下操作 1 u v d 表示将路径 (u,v) 加d 2 u v 表示询问路径 (u,v) 上点权绝对值的和 Input 第一行两个整数n和m,表 ...

  9. CodeForces 670D1 暴力或二分

    今天,开博客,,,激动,第一次啊 嗯,,先来发水题纪念一下 D1. Magic Powder - 1   This problem is given in two versions that diff ...

随机推荐

  1. spark测试脚本-笔记

    1)Spark配置&启动脚本分析 http://www.cnblogs.com/riordon/p/5732208.html

  2. Python学习 Day 3 字符串 编码 list tuple 循环 dict set

    字符串和编码 字符 ASCII Unicode UTF-8 A 1000001 00000000 01000001 1000001 中 x 01001110 00101101 11100100 101 ...

  3. R in action读书笔记(7)-第七章:基本统计分析(下)

    7.3相关 相关系数可以用来描述定量变量之间的关系.相关系数的符号(±)表明关系的方向(正相关或负相关),其值的大小表示关系的强弱程度(完全不相关时为0,完全相关时为1).除了基础安装以外,我们还将使 ...

  4. markdown表格中怎么插入逻辑或符号|?

    | 73向下投票接受 | 如果你删除反引号(****),使用|`黑客作品 a | r ------------|----- `a += x;` | r1 a |= y; | r2 并产生以下输出 在这 ...

  5. webpack3整理(第一节/满三节)

    一.css文件打包到js中(loader的三种写法) //第一种写法:直接用use. module: { rules: [{ test: /\.css$/, use: ['style-loader', ...

  6. 迅为IMX6UL开发板

    迅为iMX6UL开发板采用核心板加底板形式,核心板使用邮票孔方式连接,牢固耐用.处理器ARM®Cortex®-A7内核,运行速度高达528 MHz.512MDDR内存,8G EMMC存储,板截双网口, ...

  7. <jsp:include page="${pageContext.request.contextPath/index.jsp" ></jsp:include> 引发的错误

    路径引发的错误 如下使用项目路径对jsp页面进行获取,会报javax.servlet.ServletException: File "/web/dbwx/web/public/page_to ...

  8. 背景渐变 background-image:linear-gradient(0deg,#fff,#ccc);

    背景渐变 background-image:linear-gradient(0deg,#fff,#ccc);

  9. returnFloat_thousand() 以万计数 ,如100,结果是0.01

    function returnFloat_thousand(value){ var value=Math.ceil(Math.round(parseFloat(value)*100)/100)/100 ...

  10. centos7安装kvm虚拟机

    一 centos7安装kvm虚拟机 1.验证CPU是否支持KVM 结果中有vmx(Intel)或svm(AMD)字样,就说明CPU的支持的. [root@centos ~]# egrep '(vmx| ...