QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#660421 | #5301. Modulo Ruins the Legend | travel | WA | 25ms | 3980kb | C++14 | 1.5kb | 2024-10-20 11:06:25 | 2024-10-20 11:06:25 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> PII;
#define endl "\n"
#define ft first
#define sd second
#define pb push_back
const int MOD = 1e9 + 7;
int n,m;
int gcd(int a,int b){
if(!b) return a;
else return gcd(b,a % b);
}
int exgcd(int a,int b,int &x,int &y){
if(!b){
x = 1,y = 0;
return a;
}
int d = exgcd(b,a % b,y,x);
y -= a / b * x;
return d;
}
void solve() {
cin>>n>>m;
vector<int> v(n + 1);
int sum = 0;
for(int i = 1;i <= n;i++){
cin>>v[i];
sum = (sum + v[i]) % m;
}
int a = n,b = n * (n + 1) / 2;
int g1 = gcd(a,b),g2 = gcd(g1,m);
//int k2 = sum / g2,ans = sum - k2 * g2;
int ans = sum % g2;
int k2 = ((ans - sum + m) / g2) % m;
cout<<ans<<endl;
int k1,t;
int d1 = exgcd(g1,m ,k1,t);
// cout<<k1<<' '<<t<<' '<<g1 * k1 + m * t<<endl;
k1 *=k2;
int x1,y1;
int d2 = exgcd(a,b,x1,y1);
// cout<<x1<<' '<<y1<<endl;
// cout<<x1 * a + y1 * b <<' '<<g1<<endl;
x1 *=k1,y1 *=k1;
// cout<<x1 * a + y1 * b <<' '<<g1<<endl;
x1 = (x1 + m) % m;
y1 = (y1 + m) % m;
cout<<x1<<' '<<y1<<endl;
// cout<<ans<<' '<<sum<<' '<<k1<<' '<<k2<<endl;
// cout<<g1<<' '<<g2<<endl;
return ;
}
signed main() {
// ios::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
int T = 1;
// cin>>T;
while(T--)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3476kb
input:
6 24 1 1 4 5 1 4
output:
1 15 3
result:
ok ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3524kb
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: 3572kb
input:
1 1 0
output:
0 0 0
result:
ok ok
Test #4:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
1 1000000000 963837005
output:
0 0 36162995
result:
ok ok
Test #5:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
2 1 0 0
output:
0 0 0
result:
ok ok
Test #6:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
2 1000000000 948507269 461613424
output:
0 410120693 589879307
result:
ok ok
Test #7:
score: 0
Accepted
time: 5ms
memory: 3940kb
input:
100000 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
0 0 0
result:
ok ok
Test #8:
score: 0
Accepted
time: 25ms
memory: 3856kb
input:
100000 1000000000 253614966 278270960 980235895 498158918 928430170 216003119 852570558 948400590 239257296 897053667 294741176 38297441 382677590 406314557 609468973 854148232 314532767 738191551 158215002 5865825 920471826 380037058 356271728 749175327 28319049 208101105 953758995 896570758 521930...
output:
46613 535950000 9281
result:
ok ok
Test #9:
score: -100
Wrong Answer
time: 25ms
memory: 3980kb
input:
100000 998244353 561002596 498658036 721339539 63377827 532179242 934651519 234198881 490149304 2056307 499913682 427679408 694677560 516580968 300129454 816286800 688594301 183049581 456627420 495848352 273497462 953217060 796225499 207179832 728054671 409492082 25003432 810431468 206421553 5569626...
output:
0 877878853 839886562
result:
wrong answer Result not equal to solution.