QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#586897 | #9381. 502 Bad Gateway | Ringup | Compile Error | / | / | C++23 | 3.2kb | 2024-09-24 16:26:00 | 2024-09-24 16:26:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int n;
template<typename T>
void write(T x) {
if (x < 0) putchar('-'), x = -x;
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
template<class T>
struct Frac {
T num;
T den;
Frac(T num_, T den_) : num(num_), den(den_) {
if (den < 0) {
den = -den;
num = -num;
}
}
Frac() : Frac(0, 1) {}
Frac(T num_) : Frac(num_, 1) {}
// 输出 double value = static_cast<double>(*Frac);
explicit operator double() const {
return 1. * num / den;
}
Frac &operator+=(const Frac &rhs) {
num = num * rhs.den + rhs.num * den;
den *= rhs.den;
return *this;
}
Frac &operator-=(const Frac &rhs) {
num = num * rhs.den - rhs.num * den;
den *= rhs.den;
return *this;
}
Frac &operator*=(const Frac &rhs) {
num *= rhs.num;
den *= rhs.den;
return *this;
}
Frac &operator/=(const Frac &rhs) {
num *= rhs.den;
den *= rhs.num;
if (den < 0) {
num = -num;
den = -den;
}
return *this;
}
friend Frac operator+(Frac lhs, const Frac &rhs) {
return lhs += rhs;
}
friend Frac operator-(Frac lhs, const Frac &rhs) {
return lhs -= rhs;
}
friend Frac operator*(Frac lhs, const Frac &rhs) {
return lhs *= rhs;
}
friend Frac operator/(Frac lhs, const Frac &rhs) {
return lhs /= rhs;
}
friend Frac operator-(const Frac &a) {
return Frac(-a.num, a.den);
}
friend bool operator==(const Frac &lhs, const Frac &rhs) {
return lhs.num * rhs.den == rhs.num * lhs.den;
}
friend bool operator!=(const Frac &lhs, const Frac &rhs) {
return lhs.num * rhs.den != rhs.num * lhs.den;
}
friend bool operator<(const Frac &lhs, const Frac &rhs) {
return lhs.num * rhs.den < rhs.num * lhs.den;
}
friend bool operator>(const Frac &lhs, const Frac &rhs) {
return lhs.num * rhs.den > rhs.num * lhs.den;
}
friend bool operator<=(const Frac &lhs, const Frac &rhs) {
return lhs.num * rhs.den <= rhs.num * lhs.den;
}
friend bool operator>=(const Frac &lhs, const Frac &rhs) {
return lhs.num * rhs.den >= rhs.num * lhs.den;
}
};
__int128 S(long long x) { return (__int128)(x + 1) * x / 2; }
Frac<__int128> f(int limit)
{
__int128 s = S(limit);
Frac<__int128> ans = { (s + n) * (n - limit) + s * limit , (__int128)n * limit};
return ans;
}
void solve()
{
cin >> n;
int l = 1 , r = n;
while(r - l >= 3)
{
int lmid = l + (r - l) / 3;
int rmid = r - (r - l) / 3;
if(f(lmid) <= f(rmid)) r = rmid;
else l = lmid;
}
int ans = l;
if(f(ans) > f(l+1)) ans = l+1;
if(f(ans) > f(r)) ans = r;
Frac now = f(ans);
__int128 d = gcd(now.num , now.den);
now.num /= d; now.den /= d;
write(now.num); putchar(' '); write(now.den); putchar('\n');
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
cin >> T;
while(T--) solve();
return 0;
}
Details
In file included from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:58, from answer.code:1: /usr/include/c++/13/numeric: In instantiation of ‘constexpr std::common_type_t<_Tp1, _Tp2> std::gcd(_Mn, _Nn) [with _Mn = __int128; _Nn = __int128; common_type_t<_Tp1, _Tp2> = __int128]’: answer.code:111:21: required from here /usr/include/c++/13/numeric:166:21: error: static assertion failed: std::gcd arguments must be integers 166 | static_assert(is_integral_v<_Mn> && is_integral_v<_Nn>, | ^~~~~~~~~~~~~~~~~~ /usr/include/c++/13/numeric:166:21: note: ‘std::is_integral_v<__int128>’ evaluates to false In file included from /usr/include/c++/13/bits/stl_pair.h:60, from /usr/include/c++/13/bits/stl_algobase.h:64, from /usr/include/c++/13/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51: /usr/include/c++/13/type_traits: In instantiation of ‘struct std::make_unsigned<__int128>’: /usr/include/c++/13/type_traits:1983:11: required by substitution of ‘template<class _Tp> using std::make_unsigned_t = typename std::make_unsigned::type [with _Tp = __int128]’ /usr/include/c++/13/numeric:173:24: required from ‘constexpr std::common_type_t<_Tp1, _Tp2> std::gcd(_Mn, _Nn) [with _Mn = __int128; _Nn = __int128; common_type_t<_Tp1, _Tp2> = __int128]’ answer.code:111:21: required from here /usr/include/c++/13/type_traits:1836:62: error: invalid use of incomplete type ‘class std::__make_unsigned_selector<__int128, false, false>’ 1836 | { typedef typename __make_unsigned_selector<_Tp>::__type type; }; | ^~~~ /usr/include/c++/13/type_traits:1744:11: note: declaration of ‘class std::__make_unsigned_selector<__int128, false, false>’ 1744 | class __make_unsigned_selector; | ^~~~~~~~~~~~~~~~~~~~~~~~