abs 暴力
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 暴力的更多相关文章
- hdu-5778 abs(暴力枚举)
题目链接: abs Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Pro ...
- BestCoder Round #85 hdu5778 abs(素数筛+暴力)
abs 题意: 问题描述 给定一个数x,求正整数y,使得满足以下条件: 1.y-x的绝对值最小 2.y的质因数分解式中每个质因数均恰好出现2次. 输入描述 第一行输入一个整数T 每组数据有一行,一个整 ...
- HDU 5778 abs (素数,暴力)
题意:给定一个数x,求正整数y≥2y\geq 2y≥2,使得满足以下条件: 1.y-x的绝对值最小 2.y的质因数分解式中每个质因数均恰好出现2次. 析:由于y质因数分解式中每个质因数均出现2次,那么 ...
- HDU 5778 abs (暴力枚举)
abs Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Problem De ...
- HDU 5778 abs (BestCoder Round #85 C)素数筛+暴力
分析:y是一个无平方因子数的平方,所以可以从sqrt(x)向上向下枚举找到第一个无平方因子比较大小 大家可能觉得这样找过去暴力,但实际上无平方因子的分布式非常密集的,相关题目,可以参考 CDOJ:无平 ...
- 1250 Super Fast Fourier Transform(湘潭邀请赛 暴力 思维)
湘潭邀请赛的一题,名字叫"超级FFT"最终暴力就行,还是思维不够灵活,要吸取教训. 由于每组数据总量只有1e5这个级别,和不超过1e6,故先预处理再暴力即可. #include&l ...
- 【BZOJ-4127】Abs 树链剖分 + 线段树 (有趣的姿势)
4127: Abs Time Limit: 40 Sec Memory Limit: 256 MBSubmit: 381 Solved: 132[Submit][Status][Discuss] ...
- BZOJ4127: Abs
Description 给定一棵树,设计数据结构支持以下操作 1 u v d 表示将路径 (u,v) 加d 2 u v 表示询问路径 (u,v) 上点权绝对值的和 Input 第一行两个整数n和m,表 ...
- CodeForces 670D1 暴力或二分
今天,开博客,,,激动,第一次啊 嗯,,先来发水题纪念一下 D1. Magic Powder - 1 This problem is given in two versions that diff ...
随机推荐
- Windowsforms 中对文件操作
文件及文件夹操作: 引用命名空间:using system .IO; 1.File类: 创建:File.Create(路径);——返回FileStream FileStream fs = File.C ...
- R Programming week1-Data Type
Objects R has five basic or “atomic” classes of objects: character numeric (real numbers) integer co ...
- (转)淘淘商城系列——使用maven构建工程
http://blog.csdn.net/yerenyuan_pku/article/details/72669269 开发工具和环境 这里,我统一规范一下淘淘商城的开发工具和环境,如下: Eclip ...
- RackTables在LNMP系统的安装及使用
RackTables是一款优秀的机房管理系统,可以十分方便的登记机房设备和连接情况,非常适合小型机房的运维.RackTables是PHP开发的免费系统,最新版本为0.20.14,PHP版本要求不低于P ...
- anchor_target_layer中的bounding regression
在anchor_target层,这两行是计算bounding regression代码: bbox_targets = np.zeros((len(inds_inside), 4), dtype=np ...
- ie兼容的解决办法,6,7、8、9、10
在网站开发中不免因为各种兼容问题苦恼,针对兼容问题,其实IE给出了解决方案Google也给出了解决方案百度也应用了这种方案去解决IE的兼容问题 百度源代码如下 <!Doctype html> ...
- CSU 2018年12月月赛 G(2219): Coin
Description 有这样一个众所周知的问题: 你面前有7个硬币,其中有一个劣质的(它比正常的硬币轻一点点),你有一个天平,问需要你需要使用天平多少次能保证找到那个劣质的硬币. 众所周知的算法是: ...
- PS学习一
1.使用缩放工具时是对文档窗口进行的缩放,它只影响视图比例:而对图像的缩放则是指对图像文件本身进行的物理缩放,它会使图像的内容变大或变小. 2.分辨率是指单位长度内包含的像素点的数量,它的单位通常为像 ...
- MyBatis 多参问题
当传入的参数为多个参数时 1 可以不封装为Javabean直接传入,写法如下 public List<XXXBean> getXXXBeanList(String xxId, String ...
- 洛谷 3871 [TJOI2010]中位数
[题解] 平衡树模板题,不过因为可以离线,所以有别的做法.把询问倒着做,变成删掉数字.求中位数,于是可以二分+树状数组. #include<cstdio> #include<cstr ...