結果

問題 No.1396 Giri
ユーザー BrightLightBrightLight
提出日時 2021-02-16 18:21:52
言語 Rust
(1.77.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,388 bytes
コンパイル時間 509 ms
コンパイル使用メモリ 142,496 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-11 07:51:45
合計ジャッジ時間 2,427 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 7 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 7 ms
4,352 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 1 ms
4,356 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 1 ms
4,352 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 1 ms
4,352 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,352 KB
testcase_19 AC 4 ms
4,352 KB
testcase_20 AC 5 ms
4,372 KB
testcase_21 AC 6 ms
4,352 KB
testcase_22 AC 7 ms
4,352 KB
testcase_23 AC 7 ms
4,352 KB
testcase_24 AC 8 ms
4,348 KB
testcase_25 AC 7 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let n: usize = read();

    let (mut pvec, _) = prime_sieve(n);
    pvec.pop();

    for i in 0..pvec.len() {
        if pvec[i].pow(2) > n {
            break;
        }

        let mut pow: usize = pvec[i];
        loop {
            pow *= pvec[i];
            if pow * pvec[i] > n {
                break;
            }
        }
        pvec[i] = pow;
    }

    let mut ans: usize = 1;
    for i in 0..pvec.len() {
        ans = (ans * pvec[i]) % 998244353;
    }

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

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

// *****prime.rs (https://github.com/kgtkr/procon-lib-rs/blob/master/src/prime.rs)
// Copyright (c) 2018 tkr // MIT license
// https://github.com/kgtkr/procon-lib-rs/blob/master/LICENSE

//max以下の素数列挙
pub fn prime_sieve(n: usize) -> (Vec<usize>, Vec<bool>) {
    let mut prime = Vec::new();
    let mut is_prime = Vec::with_capacity(n + 1);
    is_prime.resize(n + 1, true);
    is_prime[0] = false;
    is_prime[1] = false;
    for i in 2..n + 1 {
        if is_prime[i] {
            prime.push(i);
            let mut j = 2 * i;
            while j <= n {
                is_prime[j] = false;
                j += i;
            }
        }
    }

  (prime, is_prime)
}
// *****end of prime.rs*****
  

0