답안 #19872

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
19872 2016-02-25T06:29:31 Z gs13068 팔찌 (kriii4_V) C++
100 / 100
932 ms 12800 KB
#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);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 12800 KB Output is correct
2 Correct 0 ms 12800 KB Output is correct
3 Correct 0 ms 12800 KB Output is correct
4 Correct 0 ms 12800 KB Output is correct
5 Correct 0 ms 12800 KB Output is correct
6 Correct 0 ms 12800 KB Output is correct
7 Correct 0 ms 12800 KB Output is correct
8 Correct 0 ms 12800 KB Output is correct
9 Correct 0 ms 12800 KB Output is correct
10 Correct 0 ms 12800 KB Output is correct
11 Correct 0 ms 12800 KB Output is correct
12 Correct 0 ms 12800 KB Output is correct
13 Correct 0 ms 12800 KB Output is correct
14 Correct 0 ms 12800 KB Output is correct
15 Correct 0 ms 12800 KB Output is correct
16 Correct 0 ms 12800 KB Output is correct
17 Correct 0 ms 12800 KB Output is correct
18 Correct 0 ms 12800 KB Output is correct
19 Correct 0 ms 12800 KB Output is correct
20 Correct 0 ms 12800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 12800 KB Output is correct
2 Correct 0 ms 12800 KB Output is correct
3 Correct 0 ms 12800 KB Output is correct
4 Correct 43 ms 12800 KB Output is correct
5 Correct 560 ms 12800 KB Output is correct
6 Correct 695 ms 12800 KB Output is correct
7 Correct 535 ms 12800 KB Output is correct
8 Correct 669 ms 12800 KB Output is correct
9 Correct 764 ms 12800 KB Output is correct
10 Correct 892 ms 12800 KB Output is correct
11 Correct 766 ms 12800 KB Output is correct
12 Correct 862 ms 12800 KB Output is correct
13 Correct 508 ms 12800 KB Output is correct
14 Correct 828 ms 12800 KB Output is correct
15 Correct 470 ms 12800 KB Output is correct
16 Correct 574 ms 12800 KB Output is correct
17 Correct 928 ms 12800 KB Output is correct
18 Correct 543 ms 12800 KB Output is correct
19 Correct 671 ms 12800 KB Output is correct
20 Correct 932 ms 12800 KB Output is correct