QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#879 | #580474 | #9381. 502 Bad Gateway | kur222 | kur222 | Failed. | 2024-09-22 15:34:29 | 2024-09-22 15:34:29 |
Details
Extra Test:
Accepted
time: 0ms
memory: 3608kb
input:
1 99999999
output:
33331835 2357
result:
ok single line: '33331835 2357'
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#580474 | #9381. 502 Bad Gateway | kur222 | AC ✓ | 662ms | 3608kb | C++23 | 3.0kb | 2024-09-21 22:01:52 | 2024-09-24 14:56:01 |
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pi=pair<int,int>;
const ll mod=998244353;
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){}
void dd()
{
ll gg=__gcd(num,den);
num/=gg;
den/=gg;
};
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*lhs.den==rhs.num*rhs.den;
}
friend bool operator!=(const Frac &lhs,const Frac &rhs){
return lhs.num*lhs.den!=rhs.num*rhs.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;
}
};
template<typename T>
void write(T x)
{
if(x<0)
putchar('-'),x=-x;
if(x>9)
write(x/10);
putchar(x%10+'0');
return;
}
using i128=__int128_t;
using fr=Frac<i128>;
void solve()
{
i128 T;
ll tt;
cin >> tt;
T=tt;
// T=1e9;
fr ans = fr(T + 1, 2);
fr now;
auto check = [&](i128 m) {
i128 num_low = m - 1;
i128 num_great = T - m + 1;
i128 total = (num_low + 1) * num_low / 2 + num_great;
if(T == num_great) {
now = fr((T + 1), 2);
} else now = fr(total, T - num_great);
// cerr << m << " " << now.num << " " << now.den << "\n";
return now + fr(1, 1) <= fr(m, 1);
};
i128 lo = 1, hi = T + 1;
while(lo < hi) {
i128 m = (lo + hi) / 2;
if(check(m)){
hi = m;
ans = min(ans, now);
}
else lo = m + 1;
}
ans.dd();
write(ans.num);
putchar(' ');
write(ans.den);
putchar('\n');
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int __=1e6;
cin>>__;
while(__--)
{
solve();
}
return 0;
}