結果

問題 No.1158 GCD Products easy
ユーザー k
提出日時 2020-08-15 07:53:46
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 700 bytes
コンパイル時間 2,096 ms
コンパイル使用メモリ 192,724 KB
最終ジャッジ日時 2025-01-13 01:08:02
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

const long long MOD = 1e9 + 7;

long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  return gcd(b, a%b);    
}

// override function template of std::gcd
long long gcd(int a, int b) {
  return gcd((long long)a, (long long)b);
}

long long solve(int a, int b, int n, int g) {
  if (n == 0)
    return g;
  long long ret = 1;
  for (int i = a; i <= b; i++) {
    ret *= solve(a, b, n-1, gcd(g, i));
    ret %= MOD;
  }
  return ret;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b, n;
  cin >> a >> b >> n;
  cout << solve(a, b, n, 0) << endl;
  
  return 0;
}
0