From 101fc7e5db000832f643dd115f333aa7b707260e Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Sun, 27 Dec 2020 19:43:35 +0800 Subject: [PATCH] =?UTF-8?q?P4449=20=E4=BA=8E=E7=A5=9E=E4=B9=8B=E6=80=92?= =?UTF-8?q?=E5=8A=A0=E5=BC=BA=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R44323990 --- problem/P4449/P4449.cpp | 59 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 problem/P4449/P4449.cpp diff --git a/problem/P4449/P4449.cpp b/problem/P4449/P4449.cpp new file mode 100644 index 00000000..f4febcdf --- /dev/null +++ b/problem/P4449/P4449.cpp @@ -0,0 +1,59 @@ +#include + +using namespace std; + +const long long N = 6000010; +const long long mod = 1000000007; + +long long n, m, k, t; +long long ans, powk[N], vis[N], f[N], pri[N], tot; + +long long qpow(long long a, long long b) { + long long res = 1; + while (b) { + if (b & 1) res = res * a % mod; + a = a * a % mod; + b >>= 1; + } + return res; +} + +void euler(long long n) { + f[1] = 1; + vis[1] = 1; + for (long long i = 2; i <= n; i++) { + if (!vis[i]) pri[++tot] = i, f[i] = (powk[i] - 1 + mod) % mod; + for (long long j = 1; j <= tot && i * pri[j] <= n; ++j) { + vis[i * pri[j]] = 1; + if (i % pri[j] == 0) { + f[i * pri[j]] = f[i] * powk[pri[j]] % mod; + break; + } + else { + f[i * pri[j]] = f[i] * f[pri[j]] % mod; + } + } + } +} + +int main() { + cin >> t >> k; + for (long long i = 1; i <= 5000000; i++) { + powk[i] = qpow(i, k); + } + euler(5000000); + for (long long i = 1; i <= 5000000; i++) { + f[i] = (f[i] + f[i - 1]) % mod; + } + while (t--) { + cin >> n >> m; + ans = 0; + for (long long l = 1, r; l <= min(n, m); l = r + 1) { + r = min(n / (n / l), m / (m / l)); + ans += (n / l) * (m / l) % mod * ((f[r] - f[l - 1] + mod) % mod) % mod; + ans %= mod; + } + cout << ans << endl; + } + return 0; +} \ No newline at end of file