結果

問題 No.1411 Hundreds of Conditions Sequences
ユーザー akakimidoriakakimidori
提出日時 2021-02-23 18:54:50
言語 Rust
(1.77.0)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 2,023 bytes
コンパイル時間 4,616 ms
コンパイル使用メモリ 169,076 KB
実行使用メモリ 26,220 KB
最終ジャッジ日時 2023-10-23 20:10:26
合計ジャッジ時間 16,730 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 1 ms
4,372 KB
testcase_04 AC 1 ms
4,372 KB
testcase_05 AC 1 ms
4,372 KB
testcase_06 AC 0 ms
4,372 KB
testcase_07 AC 1 ms
4,372 KB
testcase_08 AC 1 ms
4,372 KB
testcase_09 AC 1 ms
4,372 KB
testcase_10 AC 1 ms
4,372 KB
testcase_11 AC 1 ms
4,372 KB
testcase_12 AC 97 ms
24,264 KB
testcase_13 AC 75 ms
23,348 KB
testcase_14 AC 50 ms
20,412 KB
testcase_15 AC 78 ms
23,336 KB
testcase_16 AC 22 ms
13,272 KB
testcase_17 AC 70 ms
23,132 KB
testcase_18 AC 90 ms
24,272 KB
testcase_19 AC 98 ms
24,600 KB
testcase_20 AC 50 ms
20,548 KB
testcase_21 AC 112 ms
24,856 KB
testcase_22 AC 55 ms
21,132 KB
testcase_23 AC 102 ms
24,296 KB
testcase_24 AC 16 ms
9,920 KB
testcase_25 AC 98 ms
24,268 KB
testcase_26 AC 71 ms
23,112 KB
testcase_27 AC 50 ms
20,596 KB
testcase_28 AC 81 ms
23,732 KB
testcase_29 AC 27 ms
15,336 KB
testcase_30 AC 68 ms
22,528 KB
testcase_31 AC 63 ms
22,080 KB
testcase_32 AC 102 ms
24,636 KB
testcase_33 AC 107 ms
24,904 KB
testcase_34 AC 113 ms
24,900 KB
testcase_35 AC 105 ms
24,892 KB
testcase_36 AC 103 ms
24,900 KB
testcase_37 AC 103 ms
24,872 KB
testcase_38 AC 110 ms
24,912 KB
testcase_39 AC 105 ms
24,912 KB
testcase_40 AC 104 ms
24,892 KB
testcase_41 AC 103 ms
24,892 KB
testcase_42 AC 108 ms
24,892 KB
testcase_43 AC 106 ms
24,864 KB
testcase_44 AC 105 ms
24,884 KB
testcase_45 AC 112 ms
24,888 KB
testcase_46 AC 109 ms
24,900 KB
testcase_47 AC 107 ms
24,904 KB
testcase_48 AC 104 ms
24,900 KB
testcase_49 AC 104 ms
24,884 KB
testcase_50 AC 111 ms
24,900 KB
testcase_51 AC 108 ms
24,908 KB
testcase_52 AC 91 ms
16,444 KB
testcase_53 AC 90 ms
16,436 KB
testcase_54 AC 91 ms
16,444 KB
testcase_55 AC 89 ms
16,440 KB
testcase_56 AC 89 ms
16,436 KB
testcase_57 AC 89 ms
16,436 KB
testcase_58 AC 89 ms
16,436 KB
testcase_59 AC 91 ms
16,428 KB
testcase_60 AC 87 ms
16,440 KB
testcase_61 AC 92 ms
16,436 KB
testcase_62 AC 59 ms
10,644 KB
testcase_63 AC 85 ms
26,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn read() -> Vec<usize> {
    let mut s = String::new();
    use std::io::*;
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    it.next();
    it.flat_map(|s| s.parse()).collect()
}

const MOD: usize = 1_000_000_007;

fn pow(mut r: usize, mut n: usize) -> usize {
    let mut t = 1;
    while n > 0 {
        if n & 1 == 1 {
            t = t * r % MOD;
        }
        r = r * r % MOD;
        n >>= 1;
    }
    t
}

fn main() {
    let a = read();
    let w = *a.iter().max().unwrap();
    let mut p = (0..=w).collect::<Vec<_>>();
    for i in (2..).take_while(|p| p * p <= w) {
        if p[i] == i {
            let mut j = i * i;
            while let Some(p) = p.get_mut(j) {
                *p = i;
                j += i;
            }
        }
    }
    let factorize = |mut n: usize| -> Vec<(usize, usize)> {
        let mut f = vec![];
        while n > 1 {
            let p = p[n];
            let mut c = 0;
            while n % p == 0 {
                n /= p;
                c += 1;
            }
            f.push((p, c));
        }
        f
    };
    let mut dp = vec![(0, 0); w + 1];
    for a in a.iter() {
        for (p, c) in factorize(*a) {
            let po = &mut dp[p];
            if c > po.0 {
                *po = (c, po.0);
            } else if c > po.1 {
                po.1 = c;
            }
        }
    }
    let all = a.iter().fold(1, |s, a| s * *a % MOD);
    let lcm = dp.iter().enumerate().fold(1, |s, (k, p)| s * k.pow(p.0 as u32) % MOD);
    use std::io::Write;
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    for a in a.iter() {
        let all = all * pow(*a, MOD - 2);
        let mut lcm = lcm;
        for (p, c) in factorize(*a) {
            let (x, y) = dp[p];
            if c == x {
                lcm = lcm * pow(pow(p, MOD - 2), x - y) % MOD;
            }
        }
        let ans = (all - lcm + MOD) % MOD;
        writeln!(out, "{}", ans).ok();
    }
}
0