QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#697059 | #5301. Modulo Ruins the Legend | Godwang | WA | 0ms | 3660kb | C++23 | 1.4kb | 2024-11-01 10:04:12 | 2024-11-01 10:04:12 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define endl '\n'
#define ll long long
ll extend_gcd(ll a,ll b,ll &x,ll &y)
{
if(b==0)
{
x=1;
y=0;
return a;
}
ll d=extend_gcd(b,a%b,y,x);
y-=a/b*x;
return d;
}
const int N=1e5+10;
int tt;
ll n;
ll m;
ll sum;
int main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//freopen("ain.txt","r",stdin);freopen("aout.txt","w",stdout);
ll gcdab=0,gcdabm=0;
cin>>n>>m;
rep(i,1,n)
{
ll temp;
cin>>temp;
sum+=temp;
}
ll a=n,b=(n+1)*n/2;
gcdab=__gcd(a,b);
gcdabm=__gcd(m,__gcd( n,(1+n)*n/2 ));
ll ans=sum%gcdabm;
cout<<ans<<endl;
if(sum==ans)
{
cout<<"0 0";
exit(0);
}
ll k1,t;
extend_gcd(gcdab,m,k1,t);
//
// cout<<k1<<" "<<t<<endl;
// exit(0);
//
ll k2=(ans-sum)/gcdabm;
k2%=m;
//
k1=k1*k2;
k1%=k2;
k1+=k2;
k1%=k2;
//cout<<k1<<endl<<endl;
k1%=m;
//
//cout<<k1<<" "<<k2<<endl<<endl;
ll s,d;
extend_gcd(a,b,s,d);
//
// cout<<s<<" "<<d<<endl;
s*=k1;
d*=k1;
s%=m;s+=m;s%=m;
d%=m;d+=m;
d%=m;
cout<<s<<" "<<d;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3660kb
input:
6 24 1 1 4 5 1 4
output:
1 0 0
result:
wrong answer Result not equal to solution.