QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#699903 | #5301. Modulo Ruins the Legend | He_ng# | WA | 0ms | 3584kb | C++20 | 1.9kb | 2024-11-02 11:11:36 | 2024-11-02 11:11:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
const int N = 1e6;
const int M = 2e3;
int pow(int a, int b, int m)
{
int ans = 1;
a %= m;
while (b)
{
if (b & 1)
ans = (ans % m) * (a % m) % m;
b /= 2;
a = (a % m) * (a % m) % m;
}
ans %= m;
return ans;
}
int extgcd(int a, int b, int &x, int &y)
// 求解ax+by=gcd(a, b)
// 返回值为gcd(a, b)
{
int d = a;
if (b)
{
d = extgcd(b, a % b, y, x);
y -= (a / b) * x;
}
else
x = 1, y = 0;
return d;
}
int mod_inverse(int a, int m)
// 求解a关于模上m的逆元
// 返回-1表示逆元不存在
{
int x, y;
int d = extgcd(a, m, x, y);
return d == 1 ? (m + x % m) % m : -1;
}
void extend_gcd(int a, int b, int &d, int &x, int &y)
{
if (!b)
{
d = a;
x = 1;
y = 0;
}
else
{
extend_gcd(b, a % b, d, y, x);
y -= x * (a / b);
}
}
void solve()
{
int n, m;
cin >> n>>m;
vector<int> a(n+1);
int sum = 0;
for (int i = 1; i <= n;i++){
cin >> a[i];
sum += a[i];
}
if(sum%m==0){
cout << 0 << endl
<< 0 << " " << 0 << endl;
return;
}
int g = __gcd(n, n * (n + 1) / 2);
int k = (m - sum + g - 1) / g;
int s, d;
int t;
extend_gcd(n, n * (n + 1) / 2, t, s, d);
int b1 = n * (n + 1) / 2 / t;
int x1 = (s + b1) * (k*g / d);
x1 = (x1 % b1 + b1) % b1;
int y1 = (g * k - n * x1) / n * (n + 1) / 2;
cout
<< (sum + k * g) % m << endl;
cout << x1 << " " << y1 << endl;
return;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
//cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3584kb
input:
6 24 1 1 4 5 1 4
output:
1 1 0
result:
wrong answer Result not equal to solution.