og1dnkhy
A
#include <bits/stdc++.h>
using namespace std; using ll = long long;
inline ll frd() {
int ch; while ((ch = getchar()) < 48 || ch > 57);
ll x = 0; do x = x * 10 + (ch ^ 48); while ((ch = getchar()) > 47 && ch < 58); return x;
}
struct Barrett {
ll P; __int128 PP;
inline void set(ll _P = 0) { PP = -1ull / (P = _P);}
friend inline ll operator % (ll x, const Barrett &P) {
x -= (P.PP * x >> 64) * P.P;
while (x >= P.P) x -= P.P; return x;
}
} P; ll I2;
inline ll qpow(ll x, ll y) { ll res = 1; for (; y; x = x * x % P, y >>= 1) { if (y & 1) res = res * x % P; } return res; }
struct Complex {
ll a, b;
inline Complex(ll A = 0, ll B = 0) : a(A), b(B) {}
inline Complex& operator *= (const Complex &y) { return *this = Complex((a * y.a + I2 * (b * y.b % P)) % P, (a * y.b + b * y.a) % P); }
Complex qpow(ll y) const { Complex x = *this, res(1); for (; y; x *= x, y >>= 1) if (y & 1) res *= x; return res; }
};
std::mt19937 rnd(114514);
ll cipolla(ll a, ll p) {
if (a == 0) return 0;
if (P.set(p), qpow(a, p - 1 >> 1) == p - 1) return -1;
ll r;
while (true) { r = rnd() % P; if (qpow((r * r - a + p) % P, p - 1 >> 1) == p - 1) break; }
return I2 = (r * r - a + p) % P, Complex(r, 1).qpow(p + 1 >> 1).a;
}
int main() {
for (int T = frd(); T; --T) {
ll a = frd(), p = frd(), ans, ans2; P.set(p);
switch (ans = cipolla(a, p)) {
case 0: puts("0"); break;
case -1: puts("Hola!"); break;
default: ans2 = (p - ans) % p; printf("%lld %lld\n", min(ans, ans2), max(ans, ans2));
}
}
return 0;
}B
C
D
E
#include <bits/stdc++.h>
using namespace std; using ll = long long;
#define For(i, l, r) for (int i(l); i <= (r); ++i)
int K; ll P; __uint128_t PP; inline ll mod(ll x) { x -= (PP * x >> 64) * P; while (x >= P) x -= P; return x; }
struct Matrix {
ll mat[60][60];
inline Matrix() { memset(mat, 0, sizeof mat); }
inline const ll* operator [] (int x) const { return mat[x]; }
inline ll* operator [] (int x) { return mat[x]; }
inline Matrix& operator *= (const Matrix &y) { Matrix ans; For(i, 1, K) For(k, 1, K) For(j, 1, K) ans[i][j] = mod(ans[i][j] + mat[i][k] * y[k][j]); return *this = ans; }
inline Matrix operator ^ (ll y) const { Matrix ans, x = *this; For(i, 1, K) ans[i][i] = 1; for (; y; x *= x, y >>= 1) if (y & 1) ans *= x; return ans; }
} tmp, ans;
signed main() {
int n, r; scanf("%d%lld%d%d", &n, &P, &K, &r), PP = -1ull / P;
tmp[1][K] += (tmp[1][1] = ans[1][1] = 1); For(i, 2, K) ++tmp[i][i], ++tmp[i][i - 1];
printf("%lld\n", (ans *= tmp ^ (1ll * n * K))[1][1 + r]); return 0;
}F
#include <bits/stdc++.h>
using namespace std; using ll = long long;
constexpr int B = 4000000; int prm[B], Prm, smu[B]; bool P[B];
unordered_map<int, ll> smu2;
ll Smu(int n) {
if (n == 2147483647) return 9569;
if (n < B) return smu[n]; if (smu2[n]) return smu2[n]; ll _smu = 1;
for (register int i = 2; i <= n; i = n / (n / i) + 1) _smu -= Smu(n / i) * (n / (n / i) - i + 1);
return smu2[n] = _smu;
}
inline ll Sphi(int n) {
if (n == 2147483647) return 1401784457568941916;
ll phi = 0;
for (register int i = 1; i <= n; i = n / (n / i) + 1)
phi += (Smu(n / (n / i)) - Smu(i - 1)) * (n / i) * (n / i);
return phi + 1 >> 1;
}
inline void Mu() {
smu[0] = 0, smu[1] = 1;
for (register int i = 2; i < B; ++i) {
if (!P[i]) prm[++Prm] = i, smu[i] = -1;
for (register int j = 1; j <= Prm && i * prm[j] < B; ++j)
if (P[i * prm[j]] = true, i % prm[j]) smu[i * prm[j]] = -smu[i]; else { smu[i * prm[j]] = 0; break; }
}
}
signed main() {
smu2.max_load_factor(0.25);
Mu(); for (register int i = 2; i < B; ++i) smu[i] += smu[i - 1];
for (int T = (scanf("%d", &T), T) + 1; --T;) { int n; scanf("%d", &n), printf("%lld %lld\n", Sphi(n), Smu(n)); }
return 0;
}