QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#279243 | #5301. Modulo Ruins the Legend | one_god_and_two_dogs# | WA | 0ms | 3616kb | C++14 | 1.0kb | 2023-12-08 14:37:41 | 2023-12-08 14:37:42 |
Judging History
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;
}
详细
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.