Submission #19872

#TimeUsernameProblemLanguageResultExecution timeMemory
19872gs13068팔찌 (kriii4_V)C++98
100 / 100
932 ms12800 KiB
#include <cstdio> const int p = 1000000007; int pw(int x, int y) { return y & 1 ? (long long)pw(x, y ^ 1)*x%p : y ? pw((long long)x*x%p, y >> 1) : 1; } int a[1000001]; int c[1000001]; int d[1000001]; int main() { int i, j, t1, t2, n, m, r = 0; scanf("%d%d", &n, &m); for (i = 1; i <= n; i++) { t1 = (a[i] + pw(m, i)) % p; for (j = i; j <= n; j += i) { a[j] = (a[j] + p - t1) % p; d[j] = (d[j] + (long long)t1*(j / i)) % p; } } r = 2; for (i = 1; i <= n; i++) { d[i] = (long long)d[i] * pw(i, p - 2) % p; r = (r + d[i]) % p; if (i & 1) r = (r + pw(m, i + 1 >> 1)) % p; else r = (r + pw(m, i >> 1) * 500000004LL % p * (m + 1)) % p; } printf("%lld", r * 500000004LL % p); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...