QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#642839 | #5301. Modulo Ruins the Legend | ucup-team3474 | RE | 0ms | 0kb | C++20 | 737b | 2024-10-15 16:33:24 | 2024-10-15 16:33:24 |
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1919810;
typedef long long ll;
typedef pair<ll,ll> PII;
ll n,m,k;
ll a[N],b[N];
char s[N];
bool tf[N];
ll exgcd(ll a,ll b,ll &x,ll &y){
if(b==0){
x=1,y=0;
return a;
}
ll d=exgcd(b,a%b,y,x);
y-=(a/b)*x;
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
ll C=0;
for(int i=1;i<=n;i++) C=(C+a[i])%m;
ll a=n,b=1ll*n*(n+1)/2;
ll gg=__gcd(a,b);
// cout<<gg<<endl;
gg=__gcd(gg,m);
ll ans=C%gg;
cout<<ans<<endl;
ll nw=m+ans;
ll x,y;
exgcd(a,b,x,y);
x*=nw,y*=nw;
x%=m,y%=m;
if(x<0) x+=m;
if(y<0) y+=m;
cout<<x<<' '<<y<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
6 24 1 1 4 5 1 4
output:
1