답안 #19829

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
19829 2016-02-25T06:05:00 Z xdoju 팔찌 (kriii4_V) C++14
컴파일 오류
0 ms 0 KB
#include <cstdio>
#include <vector>
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);
}

const int N = 1000000;
long long lp[N + 1];
long long phi[N + 1];
vector<long long> pr;

void sieve() {
	phi[1] = 1;
	for (int i = 2; i <= N; ++i) {
		if (lp[i] == 0) {
			lp[i] = i;
			phi[i] = i - 1;
			pr.push_back(i);
		}
		else {
			if (lp[i] == lp[i / lp[i]]) {
				phi[i] = phi[i / lp[i]] * lp[i];
			}
			else {
				phi[i] = phi[i / lp[i]] * (lp[i] - 1);
			}
		}
		for (int j = 0; j < (int)pr.size() && pr[j] <= lp[i] && i * pr[j] <= N; ++j) {
			lp[i * pr[j]] = pr[j];
		}
	}
}

void proc() {
	sieve();

	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;

		long long lmt = (long long)(sqrt(i) + 0.00001);
		for (long long p = 1; p <= lmt; ++p) {
			if (i % p != 0) {
				continue;
			}

			t = (t + modprod(modpow(k, i / p), phi[p])) % MOD;
			if (p * p < i) {
				t = (t + modprod(modpow(k, p), phi[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;
}

Compilation message

V.cpp: In function ‘void proc()’:
V.cpp:82:37: error: ‘sqrt’ was not declared in this scope
   long long lmt = (long long)(sqrt(i) + 0.00001);
                                     ^
V.cpp:76:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld", &n, &k);
                            ^