結果

問題 No.1164 GCD Products hard
ユーザー 👑 jupirojupiro
提出日時 2020-10-20 11:34:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,820 bytes
コンパイル時間 1,295 ms
コンパイル使用メモリ 131,056 KB
実行使用メモリ 145,008 KB
最終ジャッジ日時 2023-09-28 13:39:14
合計ジャッジ時間 9,571 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;

struct mint {
	long long x;
	mint(long long x = 0) :x((x% mod + mod) % mod) {}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

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

const int N = 10'000'000;
ll cnt[N + 1];
ll fcnt[N + 1];


int main()
{

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

	ll 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--) {
		fcnt[i] += power(cnt[i], n, mod - 1);
		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;
	}
	mint res = 1;
	for (int i = 1; i <= N; i++) {
		res *= mint(i).pow(fcnt[i]);
	}
	cout << res.x << "\n";
}
0