QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#580154 | #9381. 502 Bad Gateway | asaltfish | TL | 1ms | 3632kb | C++14 | 1.6kb | 2024-09-21 20:17:40 | 2024-09-21 20:17:42 |
Judging History
answer
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string.h>
#include<iomanip>
#include<stack>
#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define ll long long
#define endl "\n"
using namespace std;
inline int read() { register int s = 0, w = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-')w = -1; ch = getchar(); }while (ch >= '0' && ch <= '9')s = s * 10 + ch - '0', ch = getchar(); return s * w; }
ll gcd(ll x,ll y)
{
return y==0?x:gcd(y,x%y);
}
void ch(ll &a,ll &b)
{
ll p=gcd(a,b);
a/=p,b/=p;
}
bool wh(pair<ll,ll>a,pair<ll,ll>b)
{
ll p=gcd(a.second,b.second);
a.first*=b.second/p,b.first*=a.second/p;
return a.first<b.first;
}
void add(ll &a,ll &b,ll a1,ll a2)
{
a*=a2,a1*=b,b*=a2;
a+=a1;
ch(a,b);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
ll t,n;
cin>>t;
while(t--)
{
cin>>n;
ll ans1=(1+n)*n/2,ans2=n;
ch(ans1,ans2);
ll a1=ans1,a2=ans2;
ans1=0,ans2=1;
//cout<<ans1<<" "<<ans2<<endl;
for(int i=1;i<=n;i++)
{
pair<ll,ll>k({a2+a1,a2});
ch(k.first,k.second);
if(wh(k,{i,1ll}))
{
add(ans1,ans2,k.first,k.second);
}
else
{
add(ans1,ans2,i,1ll);
}
//cout<<ans1<<" "<<ans2<<endl;
}
ans2*=n;
ch(ans1,ans2);
cout<<ans1<<" "<<ans2<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3632kb
input:
3 1 2 3
output:
1 1 3 2 2 1
result:
ok 3 lines
Test #2:
score: -100
Time Limit Exceeded
input:
1000000 1 1000000000 1 1 1000000000 1 1000000000 1 1 1 1000000000 1 1 1000000000 1 1000000000 1000000000 1 1000000000 1 1 1000000000 1 1000000000 1000000000 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1000000000 1 1000000000 1000000000 1000000000 1000000000 1 1 1 10000000...