QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#654810 | #5301. Modulo Ruins the Legend | wlmrh | WA | 0ms | 3860kb | C++20 | 1.7kb | 2024-10-18 22:19:44 | 2024-10-18 22:19:45 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
template<class T>
constexpr T power(T a, i64 b, i64 mod) {
T res = 1;
for (; b; b /= 2, a = a * a % mod) {
if (b % 2) {
res = res * a % mod;
}
}
return res;
}
vector<i64> get_mult1(vector<i64> mult1, vector<i64> mult2, int index1, int index2)
{// 调整系数直到一个0,一个1
if (index1 < index2) swap(index1, index2);
int is_rev = 0; // 是否index1 < index2
while (index1 != 1 and index2 != 1)
{
if (is_rev)
{
i64 m = index2 / index1;
mult2[0] -= mult1[0] * m, mult2[1] -= mult1[1] * m;
index2 -= index1 * m;
}
else
{
i64 m = index1 / index2;
mult1[0] -= mult2[0] * m, mult1[1] -= mult2[1] * m;
index1 -= index2 * m;
}
is_rev ^= 1;
}
if (index1 == 1) return mult1;
return mult2;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, m; cin >> n >> m;
int m_cpy = m;
int index1 = n, index2 = (1 + n) * n / 2;
int GCD = gcd(index1, index2); index1 /= GCD, index2 /= GCD;
// 先计算如何获得一个gcd
vector<i64> mult1(2), mult2(2); mult1[0] = mult2[1] = 1; mult1[1] = mult2[0] = 0;
mult1 = get_mult1(mult1, mult2, index1, index2);
mult1[0] = (mult1[0] % m + m) % m, mult1[1] = (mult1[1] % m + m) % m; // 把(s, d)对映射到0 ~ m 之间
i64 sum = 0;
for (int i = 0; i < n; i++)
{
int num; cin >> num;
sum += num;
}
sum %= m;
int GCD_m = gcd(GCD, m);
GCD /= GCD_m, m /= GCD_m;
i64 idx = power(GCD, m - 2, m); idx = idx % m_cpy;
mult1[0] = mult1[0] * idx % m_cpy;
mult1[1] = mult1[1] * idx % m_cpy;
cout << sum % GCD_m << endl;
cout << mult1[0] << " " << mult1[1];
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3860kb
input:
6 24 1 1 4 5 1 4
output:
1 1 21
result:
wrong answer Result not equal to solution.