QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#107065 | #5301. Modulo Ruins the Legend | Tooler_Fu | RE | 2ms | 3492kb | C++14 | 1.6kb | 2023-05-20 10:25:54 | 2023-05-20 10:25:57 |
Judging History
answer
// Problem: A. Modulo Ruins the Legend
// Contest: Codeforces - The 2022 ICPC Asia Hangzhou Regional Programming Contest
// URL: https://codeforces.com/gym/104090/problem/A
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
//MD OI赛制出Subtask是真的SB
//我是废物,我爱贺题!!!
#include<bits/stdc++.h>
using namespace std;
#define ll __int128_t
#define f(i,x,y,z) for(long long i=x;i<=y;i+=z)
#define fd(i,x,y,z) for(long long i=x;i>=y;i-=z)
ll n,m;
ll yi,er;
ll ans1,ans2;
ll sum;
inline ll rd() {
ll x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9') {
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9') {
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
inline void write(ll x) {
if(x<0) {
putchar('-');
x=-x;
}
if(x>9)
write(x/10);
putchar(x%10+'0');
}
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,x,y);
ll z=x;
x=y;
y=z-y*(a/b);
return d;
}
int main(){
n=rd(),m=rd();
f(i,1,n,1){
ll xx;
xx=rd();
sum+=xx;
sum%=m;
}
if(n==1){
puts("0");write((m-sum%m)%m);printf(" 0\n");
return 0;
}
yi=n;
er=n*(n+1)/2;
yi%=m,er%=m;
ll ff=__gcd(yi,er);
ll kk=(m-sum%m)%m;
ll hh=(kk/ff+(kk%ff==0?0:1))*ff-kk;
write(hh);
puts("");
//printf("%lld\n",hh);
if(kk==0){
printf("0 0\n");
return 0;
}
hh+=kk;
exgcd(yi,er,ans1,ans2);
ll nm=hh/ff;
ans1*=nm;
ans2*=nm;
ans1=(ans1%m+m)%m;
ans2=(ans2%m+m)%m;
write(ans1);
printf(" ");
write(ans2);
puts("");
//printf("%lld %lld\n",ans1,ans2);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3464kb
input:
6 24 1 1 4 5 1 4
output:
1 15 3
result:
ok ok
Test #2:
score: 0
Accepted
time: 2ms
memory: 3444kb
input:
7 29 1 9 1 9 8 1 0
output:
0 0 0
result:
ok ok
Test #3:
score: 0
Accepted
time: 1ms
memory: 3488kb
input:
1 1 0
output:
0 0 0
result:
ok ok
Test #4:
score: 0
Accepted
time: 0ms
memory: 3492kb
input:
1 1000000000 963837005
output:
0 36162995 0
result:
ok ok
Test #5:
score: -100
Runtime Error
input:
2 1 0 0