QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#627546 | #5301. Modulo Ruins the Legend | nahida_qaq | WA | 0ms | 3688kb | C++17 | 1.9kb | 2024-10-10 16:16:19 | 2024-10-10 16:16:20 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define io ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pb push_back
using namespace std;
const int N=1e6+5,mod1=1e9+7,mod2=998244353;
typedef pair<int,int> pi;
int a[N];
int exgcd(int a, int b, int& x, int& y)
{
if (b == 0) {
x = 1;
y = 0;
return a;
}
int d = exgcd(b, a % b, x, y);
int temp = x;
x = y;
y = temp - a / b * y;
return d;
}
void solve()
{
int n,m;
cin>>n>>m;
int sum=0;
for(int i=1;i<=n;i++)cin>>a[i],sum+=a[i];
int s0,d0;
int d1=exgcd(n,n*(n+1)/2,s0,d0);
int x0,y0;
int d2=exgcd(d1,m,x0,y0);
if(n==1)
{
cout<<0<<'\n';
cout<<m%a[1]<<' '<<0;
return ;
}
if(x0%d2==0)
{
cout<<0<<'\n';
int res=abs(x0*sum/d2);
int t=n*(n+1)/2/d1;
//cout<<t<<'\n';
s0*=res,d0*=res;
//s0=(s0%t+t)%t;
//d0=(d0%t+t)%t;
cout<<s0<<' '<<d0;
}
else
{
int w=d2/gcd(x0,d2);
int num=sum/w;
int c=min(sum-num*w,num*w+w-sum);
cout<<c<<'\n';
int res=(x0*(c-sum)/d2)*d1;
//cout<<res<<'\n';
int dd=gcd(res,gcd(n,n*(n+1)/2));
res/=dd;
int x1=n/dd,x2=n*(n+1)/2/dd;
int ss0,dd0;
int ddd=exgcd(x1,x2,ss0,dd0);
if(res<0)res=(res%m+m);
res=res/ddd;
ss0*=res,dd0*=res;
if(ss0<0)
{
ss0+=abs(ss0)/x2*x2;
dd0-=abs(ss0)/x2*x1;
if(ss0<0)ss0+=x2,dd0-=x1;
}
if(dd0<0)
{
dd0+=abs(dd0)/x1*x1;
ss0-=abs(dd0)/x1*x2;
if(dd0<0)dd0+=x1,ss0-=x2;
}
cout<<ss0<<' '<<dd0;
}
}
signed main()
{
io;
int t=1;
//cin>>t;
while(t--)
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3688kb
input:
6 24 1 1 4 5 1 4
output:
1 6 17
result:
ok ok
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3560kb
input:
7 29 1 9 1 9 8 1 0
output:
0 116 0
result:
wrong answer Integer parameter [name=s] equals to 116, violates the range [0, 28]