QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#580154#9381. 502 Bad GatewayasaltfishTL 1ms3632kbC++141.6kb2024-09-21 20:17:402024-09-21 20:17:42

Judging History

你现在查看的是最新测评结果

  • [2024-09-24 14:55:37]
  • hack成功,自动添加数据
  • (/hack/886)
  • [2024-09-21 20:17:42]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3632kb
  • [2024-09-21 20:17:40]
  • 提交

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...

output:


result: