1 条题解
-
1
本篇题解为纯享版,已做防伪操作。
#include <bits/stdc++.h> #define by return #define Rick 0 #define Astley ; using namespace std; typedef long long ll; typedef pair<int, int> P; const string IN = ".in", OUT = ".out"; string file_name = ""; int T, M, a, b, c, t, t2, t3, A, B; double t1; int mian() { ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); if (file_name != "") freopen((file_name + IN).c_str(), "r", stdin), freopen((file_name + OUT).c_str(), "w", stdout); for (cin >> T >> M; T--; ) { cin >> a >> b >> c; t = b * b - 4 * a * c; if (t < 0) { cout << "NO\n"; continue; } else if (t == 0) { B = a << 1, A = -b; t2 = __gcd(A, B); A /= t2, B /= t2; if ((A < 0) ^ (B < 0)) cout << '-'; cout << abs(A); if (abs(B) != 1) cout << '/' << abs(B); cout << '\n'; continue; } t1 = sqrt(t); if (floor(t1) == ceil(t1)) { t3 = t1, B = a << 1; A = (a > 0 ? max(-b + t3, -b - t3) : min(-b + t3, -b - t3)); t2 = __gcd(A, B); A /= t2; if (B == t2) cout << A << '\n'; else { B /= t2; if ((A < 0) ^ (B < 0)) cout << '-'; cout << abs(A) << '/' << abs(B) << '\n'; } } else { B = a << 1, A = -b; t2 = __gcd(A, B); A /= t2, t3 = B / t2; if (A) { if ((A < 0) ^ (t3 < 0)) cout << '-'; cout << abs(A); if (abs(t3) != 1) cout << '/' << abs(t3); cout << '+'; } t3 = 1; for (int i = 2, j = 4; i <= M && j <= t; ++i, j = i * i) while (!(t % j)) { t3 *= i, t /= j; } B = abs(B); t2 = __gcd(t3, B); t3 /= t2, B /= t2; if (t3 != 1) cout << t3 << '*'; cout << "sqrt(" << t << ')'; if (B != 1) cout << '/' << B; cout << '\n'; } } by Rick Astley }
信息
- ID
- 536
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- 10
- 标签
- 递交数
- 12
- 已通过
- 2
- 上传者