結果

問題 No.1164 GCD Products hard
ユーザー tonegawa
提出日時 2020-08-15 12:17:20
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2,422 ms / 2,500 ms
コード長 741 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 820 ms
コンパイル使用メモリ 87,936 KB
実行使用メモリ 82,048 KB
最終ジャッジ日時 2026-06-12 10:38:05
合計ジャッジ時間 35,753 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#define vll vector<ll>
using namespace std;
typedef long long int ll;
#define P 1000000007
#define Q 1000000006

int main() {
  ll a, b, n, ans = 1;
  scanf("%lld %lld %lld", &a, &b, &n);
  a--;
  ll cnt[b+1];
  ll ret, num, x;
  for(int g=b;g>=2;g--){
    ll tmp = b/g - a/g;
    ret = 1, num = tmp, x = n;
    for(;x;){
      if(x&1) ret = (ret*num)%Q;
      num=(num*num)%Q;
      x>>=1;
    }
    cnt[g] = ret;
    for(int k=2*g;k<=b;k+=g) cnt[g] -= cnt[k];
    ll t = abs(cnt[g])/Q + 1;
    cnt[g] = (cnt[g] + t*Q)%Q;
    ret = 1, num = g, x = cnt[g];
    for(;x;){
      if(x&1) ret = (ret*num)%P;
      num=(num*num)%P;
      x>>=1;
    }
    ans = (ans * ret)%P;
  }

  printf("%lld\n", ans);
}
0