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. jsp 页面获取当前路径

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...

  2. How do I get started with Node.js

    From: http://stackoverflow.com/questions/2353818/how-do-i-get-started-with-node-js Tutorials NodeSch ...

  3. spring 获取ApplicationContext

    第一种:获取根目录下的文件名 ApplicationContext ac = new ClassPathXmlApplicationContext("../mvc-dispatcher-se ...

  4. 深入理解java虚拟机---垃圾收集器和分配策略-1

    博文重点: 学习目标:哪些内存需要回收 什么时候回收    如何回收 在基于概念讨论的模型中,主要对Java堆和方法区进行讨论. why?:一个接口中的多个实现类需要的内存可能不一样,一个方法中的多个 ...

  5. SVG 浏览器支持

    可以参考以下链接: https://caniuse.com/#search=svg https://en.wikipedia.org/wiki/Comparison_of_layout_engines ...

  6. Poi 写入图片进入excel

    public static void cacheWritePicture(BufferedImage bufferImg, Sheet sheet, Workbook wb, int width, i ...

  7. 外键,check,索引等,根据ID来检索详细信息

    sql server OBJECTPROPERTY 函数 分类: Sql server2008-11-26 11:11 1562人阅读 评论(0) 收藏 举报 sql serverinsertdele ...

  8. viewDidLoad等相关函数调用

    viewDidLoad 此方法只有当view从nib文件初始化的时候才被调用.viewDidLoad用于初始化,加载时用到的. loadView 此方法在控制器的view为nil的时候被调用.虽然经常 ...

  9. Python3.5安装wxpython

    摘要:安装python3.X的wxpython:学习<Python基础教程>第12章“图形用户界面”时,关于升级pip和安装wxpython时遇到的一些问题和解决办法. 关于升级pip 使 ...

  10. 笔试算法题(38):并查集(Union-Find Sets)

    议题:并查集(Union-Find Sets) 分析: 一种树型数据结构,用于处理不相交集合(Disjoint Sets)的合并以及查询:一开始让所有元素独立成树,也就是只有根节点的树:然后根据需要将 ...