ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#204460 | #3605. 加法运算 | drdilyor | 100 | 257ms | 2012kb | C++ | 1.3kb | 2024-05-26 09:49:39 | 2024-05-26 12:12:17 |
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m;
int a[100005];
void exgcd(int a,int b,int &x,int &y){
if(b==0){x=1,y=0;return;}
exgcd(b,a%b,x,y);
//bx+(a-(a/b)*b)y=1.
int ty=y;
y=x-(a/b)*y;
x=ty;
}
signed main(){
cin>>n>>m;
int tt=0;
for(int i=1;i<=n;i++)cin>>a[i],tt+=a[i],tt%=m;
int p=(n+1)*n/2;p%=m;
int b=__gcd(p,m);
//b的倍数
int bb=__gcd(n,m);
int x=__gcd(b,bb);
//xp+tt%m.
int pp=(m-tt+x-1)/x;
cout<<(((m-tt+x-1)/x)*x%m+tt)%m<<"\n";
pp*=x,pp%=m;
int tx,ty;
exgcd(b,bb,tx,ty);
tx%=m,ty%=m;
//cout<<b<<" "<<bb<<" "<<pp<<" "<<tx<<" "<<ty<<"\n";
tx*=pp/__gcd(b,bb),ty*=pp/__gcd(b,bb);
b*=tx,bb*=ty;b%=m,bb%=m;
//cout<<b<<" "<<bb<<"\n";
exgcd(p,m,tx,ty);
//cout<<tx<<" "<<ty<<"\n";
//21x-24y=9
//x=5 y=4
tx+=m,tx%=m;
//21x mod 24=9.
//16+21*21%24
//
ty=(m-ty)%m;ty+=m,ty%=m;
//cout<<tx<<" "<<ty<<"\n";
tx*=(b/__gcd(p,m));
vector<int> r;r.push_back(tx%m);
exgcd(n,m,tx,ty);
tx+=m,tx%=m;
ty=(m-ty)%m;ty+=m,ty%=m;
tx*=(bb/__gcd(n,m));
cout<<tx%m<<" "<<r[0];
return 0;
//16+5*21
//d=5 s=0.
//21x 9 mod 24.
//21x 3.
//6x 0.
//p*d -my=b
//p*d+n*s+tt mod m.
//b*i+bb*j+tt mod m
//i*3+j*6=9
//bb的倍数.
for(int i=0;i<m;i++){
for(int j=0;j<m;j++)cout<<(b*i+bb*j)%m<<"\n";
}
//
//
//tt+n*(n+1)/2*d%m+s*n%m
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1240kb
input:
1000 999 57 694 144 49 433 396 584 809 979 517 854 481 761 611 117 925 925 753 41 811 256 624 782 34...
output:
0 747 0
result:
ok ok
Test #2:
score: 10
Accepted
time: 0ms
memory: 1244kb
input:
987 654 448 47 635 296 299 619 212 85 230 87 645 232 290 562 613 83 293 518 226 209 22 586 164 599 4...
output:
1 42 0
result:
ok ok
Test #3:
score: 10
Accepted
time: 0ms
memory: 1240kb
input:
966 1000 123 512 948 181 964 478 939 899 226 238 351 225 503 270 548 384 904 466 777 293 726 550 881...
output:
0 0 139
result:
ok ok
Test #4:
score: 10
Accepted
time: 39ms
memory: 2008kb
input:
99999 998244353 915422485 897548776 958894877 77577635 546953019 974096180 940328590 79518778 891928...
output:
0 148350342 0
result:
ok ok
Test #5:
score: 10
Accepted
time: 25ms
memory: 2008kb
input:
100000 10007 3844 7469 7290 5474 8451 4572 3156 4311 7543 4896 7850 4782 7329 5618 9172 7194 6440 82...
output:
0 2714 0
result:
ok ok
Test #6:
score: 10
Accepted
time: 36ms
memory: 2012kb
input:
99966 1232171 632784 843702 383299 976910 16151 934411 46078 1013107 965091 677317 642744 564897 184...
output:
0 963505 0
result:
ok ok
Test #7:
score: 10
Accepted
time: 38ms
memory: 2012kb
input:
100000 998244353 561002596 498658036 721339539 63377827 532179242 934651519 234198881 490149304 2056...
output:
0 419943281 0
result:
ok ok
Test #8:
score: 10
Accepted
time: 41ms
memory: 2012kb
input:
99999 1000000000 773048742 726584889 597425040 944388841 710710917 747919780 132563193 839347904 483...
output:
0 249914721 0
result:
ok ok
Test #9:
score: 10
Accepted
time: 40ms
memory: 1964kb
input:
93326 700644945 271553776 112572922 197003342 51054596 539660040 524912558 113000554 152111197 26324...
output:
13287 660384904 0
result:
ok ok
Test #10:
score: 10
Accepted
time: 38ms
memory: 2008kb
input:
99966 962339360 78619251 20774987 716528749 330519362 465825672 225900238 616161446 628267732 625337...
output:
15129 0 821430639
result:
ok ok
Extra Test:
score: 0
Extra Test Passed