QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#279243#5301. Modulo Ruins the Legendone_god_and_two_dogs#WA 0ms3616kbC++141.0kb2023-12-08 14:37:412023-12-08 14:37:42

Judging History

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

  • [2023-12-08 14:37:42]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3616kb
  • [2023-12-08 14:37:41]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll Exgcd(ll a, ll b, ll &x, ll &y) {
  if (!b) {
    x = 1;
    y = 0;
    return a;
  }
  ll d = Exgcd(b, a % b, x, y);
  ll t = x;
  x = y;
  y = t - (a / b) * y;
  return d;
}
ll gcd(ll a,ll b) {
  if(!b)return a;
  return gcd(b,a%b);
}
int main() {
    int n,mod;
    cin>>n>>mod;
    ll sum=0;
    for(int i=1;i<=n;i++){
        int a;cin>>a;sum+=a;
        sum%=mod;
    }
    ll A=n,B=1ll*(1+n)*n/2,x,y;
    ll g=Exgcd(A,B,x,y),k;
    if(sum==0)k=0;
    else if((mod-sum)%g==0)k=(mod-sum)/g;
    else {
      printf("%lld  %lld %lld\n ",sum,k,g);
        ll GCD=gcd(mod,g);
        ll p=sum/GCD;
        ll AA=mod/GCD,BB=g/GCD;
        ll xx,yy;
        Exgcd(AA,BB,xx,yy);
        printf("%lld %lld %lld %lld\n",AA,BB,xx,yy);
        k=-yy*p;
    }
    // printf("k=%lld,sum=%lld\n",k,sum);
    printf("%lld\n",((sum+k*g)%mod+mod)%mod);
    x=(x*k%mod+mod)%mod;
    y=(y*k%mod+mod)%mod;
    printf("%lld %lld\n",x,y);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3616kb

input:

6 24
1 1 4 5 1 4

output:

16  0 3
 8 1 0 1
1
15 19

result:

wrong answer Result not equal to solution.