1046:Square Number】的更多相关文章

总时间限制: 1000ms 内存限制: 65536kB 描述 给定正整数b,求最大的整数a,满足a*(a+b) 为完全平方数 输入 多组数据,第一行T,表示数据数.对于每组数据,一行一个正整数表示b.T <= 10^3, 1 <= b <= 10^9 输出 对于每组数据,输出最大的整数a,满足a*(a+b)为完全平方数 样例输入 3 1 3 6 样例输出 0 1 2思路:a*(a+b):gcd(a,b) = gcd(a,a+b),这个符合辗转相除,然后a*(a+b)=gcd^2(a1)*…
Square Number: Description In mathematics, a square number is an integer that is the square of an integer. In other words, it is the product of some integer with itself. For example, 9 is a square number, since it can be written as 3 * 3. Given an ar…
Description In mathematics, a square number is an integer that is the square of an integer. In other words, it is the product of some integer with itself. For example, 9 is a square number, since it can be written as 3 * 3. Given an array of distinct…
和上一题一样,把平方因子除去,然后对应的数就变成固定的 #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> using namespace std; typedef long long LL; ; const int INF=0x3f3f3f3f; ],cnt; void getprime(){ ]; memset(v,,sizeof(v)); ;i*i&…
http://acm.hdu.edu.cn/showproblem.php?pid=2281 又是一道Pell方程 化简构造以后的Pell方程为 求出其前15个解,但这些解不一定满足等式,判断后只有5个满足的情况,直接判断即可 求法可以参照上一篇日志: http://www.cnblogs.com/Felix-F/p/3223323.html struct matrix { LL ma[][]; }; ; LL nn[],xx[]; matrix operator * (matrix a,mat…
这道题首先想到的算法是DP.每个perfect square number对应的解都是1.先生成一个n+1长的DP list.对于每个i,可以用dp[i] = min(dp[j] + dp[i-j], dp[i])来更新,这里j 是<= i 的一个perfect square number.但是DP的算法超时. class Solution(object): def numSquares(self, n): """ :type n: int :rtype: int &q…
Check if a given number is a perfect square with only addition or substraction operation. eg. 25 returns true; 19 returns false. Perfect square number 有一个特性,比如0,1,4,9,16,25 他们之间的间隔分别是1,3,5,7,9,每次间隔都是i+2. 所以每次往下减i, i 更新成i+2. 看最后结果是否为0即可. import java.u…
题目链接 Problem Description There is a set including all positive integers that are not more then n. HazelFan wants to choose some integers from this set, satisfying: 1. The number of integers chosen is at least 1 and at most k. 2. The product of intege…
题目描述 In mathematics, a square number is an integer that is the square of an integer. In other words, it is the product of some integer with itself. For example, 9 is a square number, since it can be written as 3 * 3. Given an array of distinct intege…
Free from square Problem Description There is a set including all positive integers that are not more then n. HazelFan wants to choose some integers from this set, satisfying: 1. The number of integers chosen is at least 1 and at most k. 2. The produ…