QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#709307 | #5301. Modulo Ruins the Legend | _Felix | WA | 0ms | 3816kb | C++14 | 2.3kb | 2024-11-04 13:54:40 | 2024-11-04 13:54:41 |
Judging History
answer
// #define LawrenceSivan
#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
using d64 = long double;
#define INF 0x3f3f3f3f
// #define int i64
constexpr int maxn = 1e5 + 5;
constexpr int base = 131;
constexpr int mod = 1e9 + 7;
constexpr double eps = 1e-8;
namespace IO {
template<typename T>
inline void read(T &x) {
x = 0;
T f = 1;
char ch = getchar();
while (!isdigit(ch)) {if (ch == '-')f = -1; ch = getchar();}
while (isdigit(ch)) {x = x * 10 + (ch ^ 48); ch = getchar();}
x *= f;
}
template <typename T, typename... Args>
inline void read(T &t, Args &... args) {
read(t);
read(args...);
}
template<typename T>
void write(T x) {
if (x < 0)putchar('-'), x = -x;
if (x > 9)write(x / 10);
putchar(x % 10 + '0');
}
template<typename T, typename... Args>
void write(T t, Args... args) {
write(t);
putchar(' ');
write(args...);
}
}
using namespace IO;
const int N = 1e5 + 10;
typedef long long ll;
int n, m, a[N];
ll exgcd(ll a, ll b, ll &x, ll &y) {
if(b == 0) {
x = 1; y = 0;
return a;
}
ll t = exgcd(b, a % b, y, x);
y -= a / b * x;
return t;
}
void work(ll a, ll b, ll c, ll &qqq, ll &ppp) {
ll x, y;
ll g = exgcd(a, b, x, y);
x *= (c / g); y *= (c / g);
//cout<<b/g<<endl;
qqq = (x %m + m) % m;
ppp = (c - a * qqq) / b;
return;
}
inline void solve() {
int sum = 0;
cin>>n>>m;
for(int i = 1; i <= n; i++)
cin>>a[i], sum = (sum + a[i]) % m;
int g = __gcd((ll)n, (ll)n * (n + 1) / 2);
int t = __gcd(g, m);
int ze = (m - sum + t - 1) / t;
int ans = (sum + (ll)ze * t % m) % m;
printf("%d\n", ans);
//cout<<(ans + m - sum) % m<<endl;
ll s, d, k, tt;
work(g, m, ans - sum, k, tt);
work(n, (ll)n * (n + 1) / 2, (ll)k * g, s, d);
printf("%lld %lld\n", (s % m + m) % m, (d % m + m) % m);
return;
}
signed main() {
#ifdef LawrenceSivan
// freopen("a.in", "r", stdin);
freopen("a.txt", "w", stdout);
#endif
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: 3816kb
input:
6 24 1 1 4 5 1 4
output:
1 15 23
result:
wrong answer Result not equal to solution.