結果

問題 No.1164 GCD Products hard
ユーザー titia
提出日時 2025-08-19 20:14:17
言語 Rust
(1.83.0 + proconio)
結果
TLE  
実行時間 -
コード長 1,291 bytes
コンパイル時間 13,038 ms
コンパイル使用メモリ 397,832 KB
実行使用メモリ 73,508 KB
最終ジャッジ日時 2025-08-19 20:14:48
合計ジャッジ時間 23,812 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 2
other WA * 3 TLE * 4 -- * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::{self, Read};

const MOD: i64 = 1_000_000_007;

fn modpow(mut base: i64, mut exp: i64, modu: i64) -> i64 {
    let mut res: i64 = 1;
    base %= modu;
    while exp > 0 {
        if exp & 1 == 1 {
            res = res * base % modu;
        }
        base = base * base % modu;
        exp >>= 1;
    }
    res
}

fn main() {
    // 入力読み込み
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let mut iter = input.split_whitespace();
    let a: i64 = iter.next().unwrap().parse().unwrap();
    let b: i64 = iter.next().unwrap().parse().unwrap();
    let n: i64 = iter.next().unwrap().parse().unwrap();

    let mut x = vec![0i64; (b + 1) as usize];

    let _s = b - a + 1;
    for i in 2..=b {
        let ko = b / i - (a - 1) / i;
        x[i as usize] = modpow(ko, n, MOD);
    }

    for i in (1..=b).rev() {
        let mut score = 0i64;
        let mut j = i + i;
        while j <= b {
            score = (score + x[j as usize]) % MOD;
            j += i;
        }
        x[i as usize] = (x[i as usize] - score + MOD) % MOD;
    }

    let mut ans: i64 = 1;
    for i in 1..=b {
        if x[i as usize] != 0 {
            ans = ans * modpow(i, x[i as usize], MOD) % MOD;
        }
    }

    println!("{}", ans);
}
0