1 条题解
-
0
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 1e5 + 10; const int INF = 0x3f3f3f3f; int a , b , c , t , m; bool flag = 0; bool check (int d) { int x = sqrt (d); if (x * x == d) return 1; return 0; } signed main() { freopen ("uqe.in" , "r" , stdin); freopen ("uqe.out" , "w" , stdout); cin >> t >> m; while ( t-- ) { scanf ( "%lld%lld%lld" , &a , &b , &c); int d = b * b - 4 * a * c; int x = a << 1; if (d < 0) { printf ("NO\n"); continue; } // if ( b == 0 ) if (check (d)) { int ans; if (x < 0) ans = -sqrt (d) - b; else ans = sqrt (d) - b; if (ans % x == 0) printf ("%lld\n" , ans / x); else { int y = __gcd (ans , x); ans /= y; x /= y; if (x < 0) { x = -x; if (ans > 0) cout << "-"; } printf ("%lld/%lld\n" , ans , x); } } else { int ans = -b , e = 0 , y = __gcd (ans , x); if (ans != 0) { if (ans % x == 0) printf ("%lld+" , ans / x); else { ans /= y; int xx = x; xx /= y; if (xx < 0) { xx = -xx; if (ans > 0) cout << "-"; } printf ("%lld/%lld+" , ans , xx); } } for (int i = sqrt (d); i >= 1; i--) { int k = i * i; if (d % k == 0) { e = i , d /= k; break; } } if (e) { y = __gcd (e , x); e /= y; int xx = x; xx /= y; if (e < 0) e = -e; if (e == 1) { if (xx == 1) printf ("sqrt(%lld)\n" , d); else if (xx < 0) { xx = -xx; printf ("sqrt(%lld)/%lld\n" , d , xx); } else printf ("sqrt(%lld)/%lld\n" , d , xx); continue; } else if (xx == 1) printf ("%lld*sqrt(%lld)\n" , e , d); else if (xx < 0) printf ("%lld*sqrt(%lld)/%lld\n" , e , d , -xx); else printf ("%lld*sqrt(%lld)/%lld\n" , e , d , xx); } else if (x < 0) printf ("sqrt(%lld)/%lld\n" , d , -x); else printf ("sqrt(%lld)/%lld\n" , d , x); } } return 0; }
- 1
信息
- ID
- 3379
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 7
- 标签
- 递交数
- 30
- 已通过
- 9
- 上传者