HDU 5778 abs(暴力枚举)——BestCoder Round #85 1003
来源:互联网 发布:湖北省软件行业协会 编辑:程序博客网 时间:2024/06/05 19:54
传送门
abs
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1474 Accepted Submission(s): 511
Problem Description
Given a number x, ask positive integer y≥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.
1. The absolute value of y - x is minimal
2. To prime factors decomposition of Y, every element factor appears two times exactly.
Input
The first line of input is an integer T ( 1≤T≤50 )
For each test case,the single line contains, an integer x (1≤x≤1018 )
For each test case,the single line contains, an integer x (
Output
For each testcase print the absolute value of y - x
Sample Input
5
1112
4290
8716
9957
9095
Sample Output
23
65
67
244
70
Source
BestCoder Round #85
题目大意:
给定一个数 x ,求正整数y>=2 ,使得满足以下条件:1.y−x 的绝对值最小2.y 的质因数分解式中每个质因数均恰好出现2 次。
解题思路:
这个题目就是一个暴力,因为 每个质因数恰好出现两次 所以
PS: 当时没有特判
/**2016 - 08 - 05 下午Author: ITAKMotto:今日的我要超越昨日的我,明日的我要胜过今日的我,以创作出更好的代码为目标,不断地超越自己。**/#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <vector>#include <queue>#include <algorithm>#include <set>using namespace std;typedef long long LL;typedef unsigned long long ULL;const int INF = 1e9+5;const int MAXN = 1e6+5;const LL MOD = 1e4+7;const double eps = 1e-7;const double PI = acos(-1);using namespace std;bool Judge(LL x){ for(LL i=2; i*i<=x; i++) { int sum = 0; while(x%i==0) { sum++; x /= i; } if(sum > 1) return 0; } return 1;}int main(){ int T; LL x; cin>>T; while(T--) { cin>>x; if(x <= 3LL)///特判 cout<<4LL-x<<endl; else { LL p1 = (LL)sqrt(x); LL p2 = p1 + 1; while(1) { if(Judge(p1)) break; p1--; } while(1) { if(Judge(p2)) break; p2++; } LL ans1 = p1*p1; LL ans2 = p2*p2; cout<<min(abs(ans1-x), abs(ans2-x))<<endl; } } return 0;}
0 0
- HDU 5778 abs(暴力枚举)——BestCoder Round #85 1003
- HDU 5778 BestCoder Round #85 abs (暴力枚举)
- HDU 5778 abs (数学+暴力枚举)
- HDU 5778 abs (暴力枚举)
- hdu 5778 abs【暴力枚举】
- BestCoder Round #85-1003 abs
- BestCoder Round #85 1003 abs
- HDU 5778(abs 暴力)
- HDU-5778-abs(暴力)
- HDU 4956 Poor Hanamichi(暴力)——BestCoder Round #5
- Hdu 5778 abs (暴力/二分)
- BestCoder Round #50 Run 即 hdu5365(暴力枚举)
- HDU 5749 BestCoder Round #84 Colmerauer(暴力贡献)
- HDU 5147 Ferries Wheel(暴力 数组)——BestCoder Valentine's Day Round
- HDU 5479 Scaena Felix(暴力)——BestCoder Round #57(div.2)
- HDU 5522 Numbers(暴力)——BestCoder Round #61(div.2)
- HDU 5567 sequence1(暴力)——BestCoder Round #63(div.2)
- hdu——4462(暴力枚举)
- 可拉伸头部控件
- 【HDOJ 5794】A Simple Chess(大组合数Lucas定理+容斥)
- Linux网络编程【1】
- AOP 概念
- c++中set特性和如果索引类set容器的元素
- HDU 5778 abs(暴力枚举)——BestCoder Round #85 1003
- Lockdir 文件夹加密 破解
- tomcat7配置log4j解决catalina.out日志过大问题
- Effetive Objective - C 1.Objective 24 - 28 分类
- HDOJ 5792 (2016多校联合训练 Training Contest 5) World is Exploding
- 使用break直接结束外层循环
- 7种形式的Android Dialog使用举例
- 文章标题
- linux与php学习杂记