結果

問題 No.1164 GCD Products hard
ユーザー tkmst201tkmst201
提出日時 2021-01-23 10:17:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 627 ms / 2,500 ms
コード長 1,518 bytes
コンパイル時間 2,073 ms
コンパイル使用メモリ 203,264 KB
実行使用メモリ 10,140 KB
最終ジャッジ日時 2023-08-28 18:54:28
合計ジャッジ時間 12,683 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 390 ms
5,940 KB
testcase_01 AC 500 ms
6,172 KB
testcase_02 AC 361 ms
5,776 KB
testcase_03 AC 120 ms
4,376 KB
testcase_04 AC 116 ms
4,388 KB
testcase_05 AC 419 ms
6,024 KB
testcase_06 AC 495 ms
9,008 KB
testcase_07 AC 489 ms
8,704 KB
testcase_08 AC 456 ms
9,376 KB
testcase_09 AC 338 ms
5,964 KB
testcase_10 AC 123 ms
4,380 KB
testcase_11 AC 382 ms
5,872 KB
testcase_12 AC 523 ms
8,532 KB
testcase_13 AC 307 ms
5,784 KB
testcase_14 AC 268 ms
5,964 KB
testcase_15 AC 502 ms
9,788 KB
testcase_16 AC 318 ms
5,884 KB
testcase_17 AC 420 ms
6,196 KB
testcase_18 AC 362 ms
6,124 KB
testcase_19 AC 126 ms
4,380 KB
testcase_20 AC 207 ms
4,432 KB
testcase_21 AC 557 ms
9,132 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 418 ms
8,700 KB
testcase_24 AC 627 ms
10,140 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

std::vector<int> sieve(int n) {
	std::vector<int> res;
	std::vector<bool> is_prime(n + 1, true);
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i * i <= n; i++) {
		if (!is_prime[i]) continue;
		for (int j = i * i; j <= n; j += i) is_prime[j] = false;
	}
	for (int i = 2; i <= n; ++i) if (is_prime[i]) res.emplace_back(i);
	return res;
}

namespace tk {
template<typename T>
T mod_pow(T x, T n, const T & mod) {
	assert(mod > 0);
	assert(n >= 0);
	x = (x % mod + mod) % mod;
	T res = 1 % mod;
	while (n > 0) {
		if (n & 1) res = res * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}
} // namespace tk

int main() {
	int A, B, N;
	cin >> A >> B >> N;
	
	auto primes = sieve(B);
	ll ans = 1;
	for (int p : primes) {
		ll po = 0;
		for (ll p2 = p; p2 <= B; p2 *= p) po += tk::mod_pow<ll>(B / p2 - (A - 1) / p2, N, MOD - 1);
		ans = ans * tk::mod_pow<ll>(p, po, MOD) % MOD;
	}
	cout << ans << endl;
}
0