HDU - 5974 A Simple Math Problem 数论
关于 k1 k2 互质的问题,可以自己手动证明一下,需要一点数学直觉。
#pragma warning(disable:4996) #include<iostream> #include<algorithm> #include<bitset> #include<tuple> #include<unordered_map> #include<fstream> #include<iomanip> #include<string> #include<cmath> #include<cstring> #include<vector> #include<map> #include<set> #include<list> #include<queue> #include<stack> #include<sstream> #include<cstdio> #include<ctime> #include<cstdlib> #define pb push_back #define INF 0x3f3f3f3f #define inf 0x7FFFFFFF #define moD 1000000003 #define pii pair<ll,ll> #define eps 1e-8 #define equals(a,b) (fabs(a-b)<eps) #define bug puts("bug") #define re register #define fi first #define se second typedef long long ll; typedef unsigned long long ull; const ll MOD = 1e6 + 7; const int maxn = 3e5 +5; const double Inf = 10000.0; const double PI = acos(-1.0); using namespace std; ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } int main() { ll a, b, x, y; while (~scanf("%lld %lld", &a, &b)) { ll g = gcd(a, b); if (a * a - 4 * g * b < 0) { puts("No Solution"); continue; } ll del = sqrt(a * a - 4 * g * b); x = (del + a) / 2; y = a - x; if (x / gcd(x, y) * y != b) { puts("No Solution"); continue; } if (x > y) swap(x, y); printf("%lld %lld\n", x, y); } }