Submission #474635

# Submission time Handle Problem Language Result Execution time Memory
474635 2021-09-19T08:16:02 Z egod1537 팔찌 (kriii4_V) C++14
6 / 100
1000 ms 17780 KB
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll mod = 1e9 + 7;

typedef pair<ll, ll> pi;
#define var first
#define cnt second

ll pwk[1000001], phi[1000001], low[1000001];

ll pow(ll x, ll p) {
	ll ret = 1, piv = x % mod;
	while (p) {
		if (p & 1) ret *= piv;
		piv *= piv;
		ret %= mod;
		piv %= mod;
		p >>= 1;
	}
	return ret;
}
ll revmod(ll x) { return pow(x, mod - 2) % mod; }	
ll r2;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	ll n, k; cin >> n >> k;

	phi[1] = 1;
	for (int i = 2; i <= n; i++) {
		for (int j = i; j <= n; j += i) {
			if (!low[j]) low[j] = i;
		}
		phi[i] = i;
		for (int j = i; j != 1; ) {
			int p = low[j];
			while (j % p == 0) {
				j /= p;
			}
			phi[i] = (1ll * phi[i] * (p - 1)) / p;
		}
	}

	pwk[0] = 1;
	for (int i = 1; i <= 1000000; i++) pwk[i] = (pwk[i - 1] * k) % mod;
	r2 = revmod(2);

	ll ans = 2;
	for (int i = 1; i <= n; i++) {
		for (int j = i; j <= n; j += i) {
			ll diff = (((pwk[i] * phi[j / i]) % mod) * revmod(j))%mod;
			ans = (ans + diff) % mod;
		}
	}
	for (int i = 1; i <= n; i++) {
		if (i % 2 == 0) ans = (ans + (1ll * (k + 1) * pwk[i / 2] % mod) * ((mod + 1) / 2) % mod)%mod;
		else ans = (ans + pwk[i / 2 + 1])%mod;
	}
	ans *= (mod + 1) / 2;
	ans %= mod;
	cout << ans;

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8140 KB Output is correct
2 Correct 9 ms 8140 KB Output is correct
3 Correct 8 ms 8140 KB Output is correct
4 Correct 9 ms 8140 KB Output is correct
5 Correct 9 ms 8140 KB Output is correct
6 Correct 9 ms 8140 KB Output is correct
7 Correct 9 ms 8140 KB Output is correct
8 Correct 9 ms 8140 KB Output is correct
9 Correct 9 ms 8084 KB Output is correct
10 Correct 9 ms 8140 KB Output is correct
11 Correct 9 ms 8140 KB Output is correct
12 Correct 9 ms 8152 KB Output is correct
13 Correct 9 ms 8140 KB Output is correct
14 Correct 9 ms 8156 KB Output is correct
15 Correct 9 ms 8036 KB Output is correct
16 Correct 9 ms 8140 KB Output is correct
17 Correct 9 ms 8072 KB Output is correct
18 Correct 9 ms 8140 KB Output is correct
19 Correct 9 ms 8040 KB Output is correct
20 Correct 9 ms 8140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8140 KB Output is correct
2 Correct 9 ms 8124 KB Output is correct
3 Correct 10 ms 8100 KB Output is correct
4 Correct 114 ms 8988 KB Output is correct
5 Execution timed out 1092 ms 17780 KB Time limit exceeded
6 Halted 0 ms 0 KB -