c语言sscanf函数的用法是什么
234
2022-08-27
HDU 5778 BestCoder Round #85 abs (暴力枚举)
abs
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 868 Accepted Submission(s): 309
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.
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)
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
Recommend
wange2014 | We have carefully selected several similar problems for you: 5780 5779 5775 5774 5773
题意:
给定一个数x,求正整数y,使得满足以下条件: 1.y-x的绝对值最小。 2.y的质因数分解式中每个质因数均恰好出现2次。
叫你求出y-x的最小绝对值。
官方题解:由于y质因数分解式中每个质因数均出现2次,那么y是一个完全平方数,设y=z*z,题目可转换成求z,使得每个质因数出现1次. 我们可以暴力枚举z,检查z是否符合要求,显然当z是质数是符合要求,由素数定理可以得,z的枚举量在logn级别复杂度
AC代码:
#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~