結果

問題 No.1164 GCD Products hard
ユーザー milanis48663220milanis48663220
提出日時 2020-08-17 01:14:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,746 bytes
コンパイル時間 982 ms
コンパイル使用メモリ 86,476 KB
実行使用メモリ 21,512 KB
最終ジャッジ日時 2024-04-19 18:38:06
合計ジャッジ時間 12,354 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
const ll MOD = 1000000007;

template <typename T>
T pow(T a, ll n) {
	T ans = 1;
	T tmp = a;
	for (int i = 0; i <= 60; i++) {
		ll m = (ll)1 << i;
		if (m & n) {
		ans *= tmp;
		ans %= MOD;
		}
		tmp *= tmp;
		tmp %= MOD;
	}
	return ans;
}

template <typename T>
T pow_(T a, ll n) {
	T ans = 1;
	T tmp = a;
	for (int i = 0; i <= 60; i++) {
		ll m = (ll)1 << i;
		if (m & n) {
		ans *= tmp;
		ans %= (MOD-1);
		}
		tmp *= tmp;
		tmp %= (MOD-1);
	}
	return ans;
}


bool is_prime[10000001];
vector<ll> ps;

void init(){
    for(int i = 2; i <= 10000000; i++){
        is_prime[i] = true;
    }
    for(int i = 2; i*i <= 10000000; i++){
        if(is_prime[i]){
            for(int j = 2; i*j <= 10000000; j++){
                is_prime[i*j] = false;
            }
        }
    }
    for(int i = 2; i <= 10000000; i++){
        if(is_prime[i]) ps.push_back(i);
    }
}

ll A, B, N;

// [A, B]のnで割り切れる個数
ll count(ll n){
    return B/n-(A-1)/n;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    init();
    cin >> A >> B >> N;
    ll ans = 1;
    for(ll n : ps){
        ll tmp = n;
        while(tmp <= B){
            ll c = pow_<ll>(count(tmp), N)-pow_<ll>(count(tmp*n), N);
            // ll c = pow<ll>(count(tmp), N)-pow<ll>(count(tmp*n), N);
            // if(c > 0) cout << n << ' ' << count(tmp) << ' ' << count(tmp*n) << ' ' << c << endl;
            c = (c%MOD+MOD)%MOD;
            ans *= pow<ll>(tmp, c);
            ans %= MOD;
            tmp *= n;
        }
    }
    cout << ans << endl;
}
0