#include<bits/stdc++.h> #define ll long long #define db double #define gc getchar #define pc putchar
usingnamespace std;
namespace IO { template <typename T> voidread(T &x) { x = 0; bool f = 0; char c = gc(); while(!isdigit(c)) f |= c == '-', c = gc(); while(isdigit(c)) x = x * 10 + c - '0', c = gc(); if(f) x = -x; }
ll solve(int n, int m, int d) { n /= d, m /= d; if(n > m) n ^= m ^= n ^= m; ll res = 0; for(int l = 1, r; l <= n; l = r + 1) { r = min(n / (n / l), m / (m / l)); res += 1ll * (mu[r] - mu[l - 1]) * (n / l) * (m / l); } return res; }
intmain() { init(1e6); int n, m, d;; read(n), read(m), read(d); write(solve(n, m, d)), pc('\n'); return0; } // A.S.
#include<bits/stdc++.h> #define ll long long #define db double #define gc getchar #define pc putchar
usingnamespace std;
namespace IO { template <typename T> voidread(T &x) { x = 0; bool f = 0; char c = gc(); while(!isdigit(c)) f |= c == '-', c = gc(); while(isdigit(c)) x = x * 10 + c - '0', c = gc(); if(f) x = -x; }
ll calc(int n, int m) { n /= k, m /= k; int d = min(n, m); ll res = 0; for(int l = 1, r; l <= d; l = r + 1) { r = min((n / (n / l)), (m / (m / l))); res += 1ll * (sum[r] - sum[l - 1]) * (n / l) * (m / r); } return res; }
intmain() { init(N - 5); int T; read(T); while(T--) { int a, b, c, d; read(a), read(b), read(c), read(d), read(k); write(calc(b, d) - calc(a - 1, d) - calc(b, c - 1) + calc(a - 1, c - 1)), pc('\n'); } return0; } // A.S.
#include<bits/stdc++.h> #define ll long long #define db double #define gc getchar #define pc putchar
usingnamespace std;
namespace IO { template <typename T> voidread(T &x) { x = 0; bool f = 0; char c = gc(); while(!isdigit(c)) f |= c == '-', c = gc(); while(isdigit(c)) x = x * 10 + c - '0', c = gc(); if(f) x = -x; }
int n, m, a[N]; int p[N], tot, mu[N]; bool flag[N]; ll c[N], sum[N], smu[N];
voidinit() { mu[1] = 1; for(int i = 2; i <= m; i++) { if(!flag[i]) p[++tot] = i, mu[i] = -1; for(int j = 1; j <= tot && i * p[j] <= m; j++) { flag[i * p[j]] = 1; if(i % p[j] == 0) { mu[i * p[j]] = 0; break; } mu[i * p[j]] = -mu[i]; } } for(int i = 1; i <= m; i++) for(int j = i; j <= m; j += i) smu[j] = smu[j] + mu[i] * i; for(int i = 1; i <= n; i++) c[a[i]]++; for(int i = 1; i <= m; i++) for(int j = 1; j <= m / i; j++) sum[i] = sum[i] + j * c[i * j]; for(int i = 1; i <= m; i++) sum[i] = sum[i] * sum[i]; return; }
signedmain() { read(n); for(int i = 1; i <= n; i++) read(a[i]), m = max(m, a[i]); init(); ll ans = 0; for(int i = 1; i <= m; i++) ans += i * smu[i] * sum[i]; write(ans), pc('\n'); return0; } // A.S.
#include<bits/stdc++.h> #define ll long long #define db double #define gc getchar #define pc putchar
usingnamespace std;
namespace IO { template <typename T> voidread(T &x) { x = 0; bool f = 0; char c = gc(); while(!isdigit(c)) f |= c == '-', c = gc(); while(isdigit(c)) x = x * 10 + c - '0', c = gc(); if(f) x = -x; }
constint N = 2e5 + 5; constint M = 1e6 + 5; constint mod = 998244353;
ll add(ll x){return x < mod ? x : x - mod;} ll sub(ll x){return x < 0 ? x : x + mod;} ll qpow(ll a, int b) { ll res = 1; while(b) { if(b & 1) res = res * a % mod; a = a * a % mod, b >>= 1; } return res; }
int n, m, a[N]; int p[M], tot, mu[M]; bool flag[M]; ll c[M], sum[M], smu[M];
voidinit() { mu[1] = 1; for(int i = 2; i <= m; i++) { if(!flag[i]) p[++tot] = i, mu[i] = -1; for(int j = 1; j <= tot && i * p[j] <= m; j++) { flag[i * p[j]] = 1; if(i % p[j] == 0) { mu[i * p[j]] = 0; break; } mu[i * p[j]] = -mu[i]; } } for(int i = 1; i <= m; i++) for(int j = i; j <= m; j += i) smu[j] = add((smu[j] + mu[i] * i % mod) % mod + mod); for(int i = 1; i <= n; i++) c[a[i]]++; for(int i = 1; i <= m; i++) for(int j = 1; j <= m / i; j++) sum[i] = add(sum[i] + j * c[i * j] % mod); for(int i = 1; i <= m; i++) sum[i] = sum[i] * sum[i] % mod; return; }
signedmain() { read(n); for(int i = 1; i <= n; i++) read(a[i]), m = max(m, a[i]); init(); ll ans = 0; for(int i = 1; i <= m; i++) ans = ((ans + i * smu[i] % mod * sum[i] % mod) % mod + mod) % mod; for(int i = 1; i <= n; i++) ans = ((ans - a[i]) % mod + mod) % mod; ans = ans * qpow(2, mod - 2) % mod; write(ans), pc('\n'); return0; } // A.S.
#include<bits/stdc++.h> #define ll long long #define db double #define gc getchar #define pc putchar
usingnamespace std;
namespace IO { template <typename T> voidread(T &x) { x = 0; bool f = 0; char c = gc(); while(!isdigit(c)) f |= c == '-', c = gc(); while(isdigit(c)) x = x * 10 + c - '0', c = gc(); if(f) x = -x; }
intcalc(int n) { int ans = qpow(fac[n], n << 1), res = 1; for(int l = 1, r; l <= n; l = r + 1) { r = n / (n / l); res = 1ll * res * qpow(1ll * fac[r] * qpow(fac[l - 1], p - 2) % p, 2 * phi[n / l] - 1) % p; } return1ll * ans * qpow(1ll * res * res % p, p - 2) % p; }
#include<bits/stdc++.h> #define ll long long #define db double #define gc getchar #define pc putchar
usingnamespace std;
namespace IO { template <typename T> voidread(T &x) { x = 0; bool f = 0; char c = gc(); while(!isdigit(c)) f |= c == '-', c = gc(); while(isdigit(c)) x = x * 10 + c - '0', c = gc(); if(f) x = -x; }
for(int i = 1; i <= n; i++) { for(int l = 1, r; l <= i; l = r + 1) { r = i / (i / l); sum[i] += 1ll * (r - l + 1) * (i / l); } } return; }
ll calc(int n, int m) { ll res = 0; int mn = min(n, m); for(int l = 1, r; l <= mn; l = r + 1) { r = min(n / (n / l), m / (m / l)); res += (mu[r] - mu[l - 1]) * sum[n / l] * sum[m / l]; } return res; }
intmain() { init(5e4); int T; read(T); while(T--) { int n, m; read(n), read(m); write(calc(n, m)), pc('\n'); } return0; } // A.S.
#include<bits/stdc++.h> #define int long long #define db double #define gc getchar #define pc putchar
usingnamespace std;
namespace IO { template <typename T> voidread(T &x) { x = 0; bool f = 0; char c = gc(); while(!isdigit(c)) f |= c == '-', c = gc(); while(isdigit(c)) x = x * 10 + c - '0', c = gc(); if(f) x = -x; }
voidinit(int n, int m) { mu[1] = 1; for(int i = 2; i <= n; i++) { if(!flag[i]) p[++tot] = i, mu[i] = -1; for(int j = 1; j <= tot && i * p[j] <= n; j++) { flag[i * p[j]] = 1; if(i % p[j] == 0) { mu[i * p[j]] = 0; break; } mu[i * p[j]] = -mu[i]; } } for(int i = 1; i <= n; i++) sum[i] = (sum[i - 1] + i * i % mod * (mu[i] + mod) % mod) % mod; return; }
intgetsum(int n, int m) { return (n * (n + 1) / 2 % mod) * (m * (m + 1) / 2 % mod) % mod; }
intcalc(int n, int m) { int res = 0; for(int l = 1, r; l <= n; l = r + 1) { r = min(n / (n / l), m / (m / l)); res = (res + (sum[r] - sum[l - 1] + mod) * getsum(n / l, m / l) % mod) % mod; } return res; }
intsolve(int n, int m) { int res = 0; for(int l = 1, r; l <= n; l = r + 1) { r = min(n / (n / l), m / (m / l)); res = (res + ((l + r) * (r - l + 1) / 2 % mod) * calc(n / l, m / l) % mod) % mod; } return res; }
signedmain() { int n, m; read(n), read(m); if(n > m) n ^= m ^= n ^= m; init(n, m); write(solve(n, m)), pc('\n'); return0; } // A.S.
#include<bits/stdc++.h> #define ll long long #define db double #define gc getchar #define pc putchar
usingnamespace std;
namespace IO { template <typename T> voidread(T &x) { x = 0; bool f = 0; char c = gc(); while(!isdigit(c)) f |= c == '-', c = gc(); while(isdigit(c)) x = x * 10 + c - '0', c = gc(); if(f) x = -x; }
#include<bits/stdc++.h> #define ll long long #define db double #define gc getchar #define pc putchar
usingnamespace std;
namespace IO { template <typename T> voidread(T &x) { x = 0; bool f = 0; char c = gc(); while(!isdigit(c)) f |= c == '-', c = gc(); while(isdigit(c)) x = x * 10 + c - '0', c = gc(); if(f) x = -x; }
ll solve(int n, int m) { ll res = 1; for(int l = 1, r; l <= n; l = r + 1) { r = min(n / (n / l), m / (m / l)); res = res * qpow(pro[r] * qpow(pro[l - 1], mod - 2) % mod, 1ll * (n / l) * (m / l) % (mod - 1)) % mod; } return res; }
intmain() { init(1e6); int T; read(T); while(T--) { int n, m; read(n), read(m); if(n > m) n ^= m ^= n ^= m; write(solve(n, m)), pc('\n'); } return0; } // A.S.
#include<bits/stdc++.h> #define ll long long #define db double #define gc getchar #define pc putchar
usingnamespace std;
namespace IO { template <typename T> voidread(T &x) { x = 0; bool f = 0; char c = gc(); while(!isdigit(c)) f |= c == '-', c = gc(); while(isdigit(c)) x = x * 10 + c - '0', c = gc(); if(f) x = -x; }
ll solve(int n, int m) { if(n > m) n ^= m ^= n ^= m; ll res = 0; for(int l = 1, r; l <= n; l = r + 1) { r = min(n / (n / l), m / (m / l)); res += 1ll * (sum[r] - sum[l - 1]) * (n / l) * (m / l); } return res; }
intmain() { init(1e7); int T; read(T); while(T--) { int n, m; read(n), read(m); write(solve(n, m)), pc('\n'); } return0; } // A.S.