結果

問題 No.1164 GCD Products hard
ユーザー 👑 jupirojupiro
提出日時 2020-10-20 12:02:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,159 bytes
コンパイル時間 2,200 ms
コンパイル使用メモリ 144,116 KB
実行使用メモリ 95,004 KB
最終ジャッジ日時 2024-07-21 08:21:49
合計ジャッジ時間 45,913 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,000 ms
57,984 KB
testcase_01 AC 2,278 ms
64,128 KB
testcase_02 AC 1,654 ms
48,384 KB
testcase_03 AC 897 ms
19,072 KB
testcase_04 AC 703 ms
15,616 KB
testcase_05 AC 2,074 ms
57,344 KB
testcase_06 AC 2,074 ms
68,096 KB
testcase_07 AC 2,090 ms
70,144 KB
testcase_08 AC 2,014 ms
67,328 KB
testcase_09 AC 1,713 ms
50,432 KB
testcase_10 AC 843 ms
17,536 KB
testcase_11 AC 1,673 ms
53,376 KB
testcase_12 AC 2,374 ms
67,968 KB
testcase_13 AC 1,510 ms
42,368 KB
testcase_14 AC 891 ms
24,064 KB
testcase_15 AC 2,047 ms
69,504 KB
testcase_16 AC 1,086 ms
34,816 KB
testcase_17 AC 1,935 ms
55,680 KB
testcase_18 AC 1,834 ms
51,328 KB
testcase_19 AC 700 ms
15,104 KB
testcase_20 AC 1,129 ms
29,184 KB
testcase_21 AC 2,454 ms
86,220 KB
testcase_22 AC 304 ms
5,376 KB
testcase_23 AC 328 ms
5,376 KB
testcase_24 TLE -
testcase_25 AC 295 ms
5,376 KB
testcase_26 AC 301 ms
5,376 KB
testcase_27 AC 299 ms
5,376 KB
testcase_28 AC 329 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;
using ull = unsigned long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353;
constexpr int MAX = 1100000;

int power(int x, int n, int p) {
	if (n == 0) {
		return 1;
	}
	if (n % 2 == 0) {
		return power(1LL * x * x % p, n / 2, p);
	}
	else {
		return 1LL * x * power(x, n - 1, p) % p;
	}
}

const int N = 10'000'000;
int cnt[N + 1];
int fcnt[N + 1];
bool done[N + 1];
int f[N + 1];

int main()
{

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int a, b, n; cin >> a >> b >> n;
	for (int i = 1; i <= N; i++) {
		for (int j = i; j <= N; j += i) {
			if(a<= j and j <= b) cnt[i] += 1;
		}
	}
	
	for (int i = N; i >= 1; i--) {
		if (cnt[i] == 0) continue;
		if (done[cnt[i]]) fcnt[i] = f[cnt[i]];
		else {
			fcnt[i] = power(cnt[i], n, mod - 1);
			done[cnt[i]] = true;
			f[cnt[i]] = fcnt[i];
		}
		for (int j = i + i; j <= N; j += i) {
			fcnt[i] -= fcnt[j];
			if (fcnt[i] < 0) fcnt[i] += mod - 1;
		}
		//cout << i << " " << fcnt[i] << endl;
	}
	int res = 1;
	
	for (int i = 1; i <= N; i++) {
		res = 1LL * res * power(i, fcnt[i], mod) % mod;
	}
	cout << res << "\n";
}
0