QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#659010 | #5301. Modulo Ruins the Legend | SYease | WA | 0ms | 3604kb | C++17 | 1.6kb | 2024-10-19 18:13:42 | 2024-10-19 18:13:42 |
Judging History
answer
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<set>
#include<cmath>
#include<queue>
#define int long long
#define endl '\n'
#define F first
#define S second
#define sz size()
#define B begin()
#define D end()
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(false)
using namespace std;
const int N=1e6+10;
const int mod=1e9+7;
int ksm(int m,int k,int mod);
int gcd(int a,int b);
int exgcd(int a,int b,int &x,int &y);
int n,m;
int a[N];
void solve()
{
cin>>n>>m;
int sum=0;
for(int i=1;i<=n;i++){
int a;
cin>>a;
sum+=a;
}
int k=gcd(n,n*(n+1)/2);
int g=gcd(k,m);
int f=(-sum)/g;
int ans_f=f*g;
int ans=ans_f+sum;
int x,y;
exgcd(k,m,x,y);
x*=f;
y*=f;
int s,d;
exgcd(n,(n+1)*n/2,s,d);
s=s/g*(ans_f-m*y);
d=d/g*(ans_f-m*y);
cout<<ans<<endl;
cout<<s<<' '<<d<<endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int tc=1;
//cin>>tc;
while(tc--)
{
solve();
}
return 0;
}
int ksm(int m,int k,int mod)
{
int ans=1;
int t=m;
while(k)
{
if(k&1) ans=ans*t%mod;
t=t*t%mod;
k>>=1;
}
return ans;
}
int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
int exgcd(int a,int b,int& x,int& y)
{
if(b==0){
x=1,y=0;
return a;//返回值为gcd(a,b)
}
int res=exgcd(b,a%b,x,y);//迭代到最底层
int t=x;
x=y;
y=t-(a/b)*y;
//完成实现时的x1=y2,y1=x2-(a/b)*y2
//由于是从最深层实现的,故直接用公式向上层传递即可
return res;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3604kb
input:
6 24 1 1 4 5 1 4
output:
1 15 0
result:
wrong answer Result not equal to solution.