摘要:
这题给定一个N,求最小的x^2满足y^2 = x^2 + N;将x^2移到左边,得到(y+x)*(y-x) = N,于是我们分解N成两个约数相乘的形式,于是我们从sqrt(N)到1开始枚举约数,得到可以相除的约数对(a, b)后,直接计算abs((a-b) / 2)就是x的值了,当然x不能为零,并且a,b的奇偶性要一致。代码如下:#include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm>#include<cmath>#include<queue&g 阅读全文
摘要:
#include <cstdio>#include <cstring>#include <cstdlib>#include <iostream>#include <algorithm>using namespace std;int gcd(int a, int b) { return b ? gcd(b, a % b) : a;}int main() { int a, b; while (scanf("%d %d", &a, &b) == 2) { printf("%d + %d = %d 阅读全文