結果
| 問題 | No.1164 GCD Products hard |
| ユーザー |
milanis48663220
|
| 提出日時 | 2020-08-17 01:15:57 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 655 ms / 2,500 ms |
| コード長 | 1,758 bytes |
| 記録 | |
| コンパイル時間 | 923 ms |
| コンパイル使用メモリ | 86,088 KB |
| 実行使用メモリ | 21,380 KB |
| 最終ジャッジ日時 | 2024-10-11 10:47:57 |
| 合計ジャッジ時間 | 13,874 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 27 |
ソースコード
#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-1)+(MOD-1))%(MOD-1);
ans *= pow<ll>(tmp, c);
ans %= MOD;
tmp *= n;
}
}
cout << ans << endl;
}
milanis48663220