답안 #19819

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
19819 2016-02-25T05:55:15 Z xdoju 팔찌 (kriii4_V) C++14
6 / 100
1000 ms 1084 KB
#include <cstdio>
using namespace std;

const long long MOD = 1000000007ll;

long long modpow(long long r, long long n) {
	long long ret = 1;
	while (n > 0) {
		if (n % 2 > 0) {
			ret = (ret * r) % MOD;
		}
		r = (r * r) % MOD;
		n /= 2;
	}
	return ret;
}

long long modinv(long long n) {
	return modpow(n, MOD - 2);
}

long long modprod(long long a, long long b) {
	a = a % MOD;
	b = b % MOD;
	return (a * b) % MOD;
}

long long modprod(long long a, long long b, long long c) {
	c = c % MOD;
	return (modprod(a, b) * c) % MOD;
}

long long moddiv(long long a, long long b) {
	return (a * modinv(b)) % MOD;
}

long long gcd(long long a, long long b) {
	if (a < b) {
		return gcd(b, a);
	}
	return (b == 0) ? a : gcd(b, a % b);
}

void proc() {
	long long n, k;
	scanf("%lld %lld", &n, &k);

	long long ans = 1;
	for (long long i = 1; i <= n; ++i) {
		long long t = 0;
		for (long long p = 1; p <= i; ++p) {
			t = (t + modpow(k, gcd(i, p))) % MOD;
		}
		t = moddiv(t, i);


		long long u = 0;
		if (i % 2 == 0) {
			u = moddiv(t, 2);
			long long v = modprod(k + 1, modpow(k, i / 2));
			v = moddiv(v, 4);
			u = (u + v) % MOD;
		}
		else {
			u = moddiv(t, 2);
			long long v = modpow(k, (i + 1) / 2);
			v = moddiv(v, 2);
			u = (u + v) % MOD;
		}

		ans = (ans + u) % MOD;
	}
	printf("%lld", ans);
}

int main() {
	//freopen("input.txt", "r", stdin);
	proc();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1084 KB Output is correct
2 Correct 0 ms 1084 KB Output is correct
3 Correct 0 ms 1084 KB Output is correct
4 Correct 0 ms 1084 KB Output is correct
5 Correct 0 ms 1084 KB Output is correct
6 Correct 0 ms 1084 KB Output is correct
7 Correct 0 ms 1084 KB Output is correct
8 Correct 0 ms 1084 KB Output is correct
9 Correct 0 ms 1084 KB Output is correct
10 Correct 0 ms 1084 KB Output is correct
11 Correct 0 ms 1084 KB Output is correct
12 Correct 0 ms 1084 KB Output is correct
13 Correct 0 ms 1084 KB Output is correct
14 Correct 0 ms 1084 KB Output is correct
15 Correct 0 ms 1084 KB Output is correct
16 Correct 0 ms 1084 KB Output is correct
17 Correct 0 ms 1084 KB Output is correct
18 Correct 0 ms 1084 KB Output is correct
19 Correct 0 ms 1084 KB Output is correct
20 Correct 0 ms 1084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1084 KB Output is correct
2 Correct 20 ms 1084 KB Output is correct
3 Correct 105 ms 1084 KB Output is correct
4 Execution timed out 1000 ms 1080 KB Program timed out
5 Halted 0 ms 0 KB -