QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#627508 | #5301. Modulo Ruins the Legend | nahida_qaq | WA | 0ms | 3632kb | C++17 | 1.7kb | 2024-10-10 16:10:04 | 2024-10-10 16:10:04 |
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(x0%d2==0)
{
cout<<0<<'\n';
int res=abs(x0*sum/d2);
int t=n*(n+1)/2/d1;
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: 3624kb
input:
6 24 1 1 4 5 1 4
output:
1 6 17
result:
ok ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
7 29 1 9 1 9 8 1 0
output:
0 0 0
result:
ok ok
Test #3:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
1 1 0
output:
0 0 0
result:
ok ok
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3624kb
input:
1 1000000000 963837005
output:
0 0 0
result:
wrong answer Result not equal to solution.