QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#580195#9381. 502 Bad GatewayasaltfishWA 188ms3580kbC++141.8kb2024-09-21 20:27:232024-09-21 20:27:30

Judging History

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

  • [2024-09-24 14:55:37]
  • hack成功,自动添加数据
  • (/hack/886)
  • [2024-09-21 20:27:30]
  • 评测
  • 测评结果:WA
  • 用时:188ms
  • 内存:3580kb
  • [2024-09-21 20:27:23]
  • 提交

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;
        ll en=a1/a2+1;
        ans1=(1+en)*en/2+n-en;
        a1*=(n-en);
        add(ans1,ans2,a1,a2);
        ch(ans1,ans2);
        ans2*=n;
        ch(ans1,ans2);
        // 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: 0ms
memory: 3576kb

input:

3
1
2
3

output:

1 1
3 2
2 1

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 188ms
memory: 3580kb

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:

1 1
750000001999999999 2000000000
1 1
1 1
750000001999999999 2000000000
1 1
750000001999999999 2000000000
1 1
1 1
1 1
750000001999999999 2000000000
1 1
1 1
750000001999999999 2000000000
1 1
750000001999999999 2000000000
750000001999999999 2000000000
1 1
750000001999999999 2000000000
1 1
1 1
75000000...

result:

wrong answer 2nd lines differ - expected: '1999961560 44721', found: '750000001999999999 2000000000'