提出 #54072369


ソースコード 拡げる

fn main() {
    let k = read::<u64>();

    let sieve = SieveOfEratosthenes::new(1_000_000);
    let factors = sieve.factorize(k);

    let mut ans = 1;
    for &(p, e) in factors.iter() {
        let mut v = 0;
        let mut c = 0;
        while c < e {
            v += p;
            let mut x = v;
            while x % p == 0 {
                x /= p;
                c += 1;
            }
        }
        ans = std::cmp::max(ans, v);
    }

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

struct SieveOfEratosthenes {
    primes: Vec<u64>,
}

impl SieveOfEratosthenes {
    fn new(v: usize) -> Self {
        let mut is_prime = vec![true; v + 1];
        let mut primes = vec![];
        for i in 2..=v {
            if is_prime[i] {
                primes.push(i as u64);
                for j in ((i * i)..=v).step_by(i) {
                    is_prime[j] = false;
                }
            }
        }
        Self { primes }
    }

    fn factorize(&self, mut x: u64) -> Vec<(u64, u64)> {
        assert!(x > 1);
        let mut res = vec![];
        for &p in self.primes.iter() {
            let mut exp = 0;
            while x % p == 0 {
                exp += 1;
                x = x / p;
            }
            if exp > 0 {
                res.push((p, exp))
            }
            if p * p > x {
                break;
            }
        }
        if x > 1 {
            res.push((x, 1));
        }
        res
    }
}

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()
}

提出情報

提出日時
問題 D - Factorial and Multiple
ユーザ amoshuangyc
言語 Rust (rustc 1.70.0)
得点 400
コード長 1657 Byte
結果 AC
実行時間 6 ms
メモリ 3576 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 3
AC × 63
セット名 テストケース
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, hand_15.txt, hand_16.txt, hand_17.txt, hand_18.txt, hand_19.txt, hand_20.txt, hand_21.txt, hand_22.txt, hand_23.txt, hand_24.txt, hand_25.txt, hand_26.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 6 ms 3520 KiB
example_01.txt AC 6 ms 3560 KiB
example_02.txt AC 6 ms 3484 KiB
hand_00.txt AC 6 ms 3464 KiB
hand_01.txt AC 5 ms 3332 KiB
hand_02.txt AC 6 ms 3448 KiB
hand_03.txt AC 6 ms 3396 KiB
hand_04.txt AC 6 ms 3552 KiB
hand_05.txt AC 6 ms 3508 KiB
hand_06.txt AC 6 ms 3576 KiB
hand_07.txt AC 6 ms 3504 KiB
hand_08.txt AC 6 ms 3400 KiB
hand_09.txt AC 6 ms 3440 KiB
hand_10.txt AC 6 ms 3404 KiB
hand_11.txt AC 5 ms 3464 KiB
hand_12.txt AC 6 ms 3348 KiB
hand_13.txt AC 6 ms 3496 KiB
hand_14.txt AC 6 ms 3412 KiB
hand_15.txt AC 6 ms 3556 KiB
hand_16.txt AC 6 ms 3420 KiB
hand_17.txt AC 5 ms 3460 KiB
hand_18.txt AC 6 ms 3424 KiB
hand_19.txt AC 6 ms 3532 KiB
hand_20.txt AC 6 ms 3500 KiB
hand_21.txt AC 6 ms 3516 KiB
hand_22.txt AC 6 ms 3468 KiB
hand_23.txt AC 6 ms 3492 KiB
hand_24.txt AC 6 ms 3372 KiB
hand_25.txt AC 6 ms 3436 KiB
hand_26.txt AC 6 ms 3516 KiB
random_00.txt AC 6 ms 3340 KiB
random_01.txt AC 6 ms 3556 KiB
random_02.txt AC 6 ms 3528 KiB
random_03.txt AC 6 ms 3380 KiB
random_04.txt AC 6 ms 3532 KiB
random_05.txt AC 5 ms 3472 KiB
random_06.txt AC 6 ms 3356 KiB
random_07.txt AC 6 ms 3556 KiB
random_08.txt AC 5 ms 3472 KiB
random_09.txt AC 6 ms 3544 KiB
random_10.txt AC 6 ms 3404 KiB
random_11.txt AC 6 ms 3488 KiB
random_12.txt AC 5 ms 3468 KiB
random_13.txt AC 6 ms 3488 KiB
random_14.txt AC 5 ms 3460 KiB
random_15.txt AC 6 ms 3364 KiB
random_16.txt AC 6 ms 3488 KiB
random_17.txt AC 5 ms 3460 KiB
random_18.txt AC 5 ms 3524 KiB
random_19.txt AC 5 ms 3480 KiB
random_20.txt AC 5 ms 3548 KiB
random_21.txt AC 5 ms 3448 KiB
random_22.txt AC 5 ms 3528 KiB
random_23.txt AC 5 ms 3456 KiB
random_24.txt AC 6 ms 3472 KiB
random_25.txt AC 6 ms 3500 KiB
random_26.txt AC 6 ms 3432 KiB
random_27.txt AC 5 ms 3408 KiB
random_28.txt AC 5 ms 3420 KiB
random_29.txt AC 6 ms 3564 KiB
random_30.txt AC 6 ms 3496 KiB
random_31.txt AC 6 ms 3480 KiB
random_32.txt AC 6 ms 3372 KiB