結果

問題 No.1567 Integer Coefficient Equation
ユーザー koba-e964koba-e964
提出日時 2021-11-15 19:46:59
言語 Rust
(1.77.0)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 2,316 bytes
コンパイル時間 1,586 ms
コンパイル使用メモリ 154,444 KB
実行使用メモリ 7,756 KB
最終ジャッジ日時 2023-08-21 14:27:07
合計ジャッジ時間 8,380 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
6,632 KB
testcase_01 AC 46 ms
6,700 KB
testcase_02 AC 77 ms
7,664 KB
testcase_03 AC 74 ms
7,636 KB
testcase_04 AC 75 ms
7,596 KB
testcase_05 AC 77 ms
7,596 KB
testcase_06 AC 75 ms
7,676 KB
testcase_07 AC 45 ms
6,632 KB
testcase_08 AC 46 ms
6,684 KB
testcase_09 AC 45 ms
6,624 KB
testcase_10 AC 44 ms
6,540 KB
testcase_11 AC 46 ms
6,620 KB
testcase_12 AC 46 ms
6,636 KB
testcase_13 AC 45 ms
6,624 KB
testcase_14 AC 45 ms
6,628 KB
testcase_15 AC 46 ms
6,644 KB
testcase_16 AC 45 ms
6,552 KB
testcase_17 AC 103 ms
7,752 KB
testcase_18 AC 102 ms
7,684 KB
testcase_19 AC 103 ms
7,688 KB
testcase_20 AC 103 ms
7,756 KB
testcase_21 AC 102 ms
7,740 KB
testcase_22 AC 102 ms
7,680 KB
testcase_23 AC 102 ms
7,688 KB
testcase_24 AC 103 ms
7,664 KB
testcase_25 AC 102 ms
7,680 KB
testcase_26 AC 102 ms
7,680 KB
testcase_27 AC 102 ms
7,688 KB
testcase_28 AC 102 ms
7,728 KB
testcase_29 AC 103 ms
7,696 KB
testcase_30 AC 101 ms
7,680 KB
testcase_31 AC 102 ms
7,592 KB
testcase_32 AC 101 ms
7,616 KB
testcase_33 AC 102 ms
7,684 KB
testcase_34 AC 102 ms
7,672 KB
testcase_35 AC 102 ms
7,748 KB
testcase_36 AC 101 ms
7,636 KB
testcase_37 AC 101 ms
7,680 KB
testcase_38 AC 102 ms
7,676 KB
testcase_39 AC 98 ms
7,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => { ($(read_value!($next, $t)),*) };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {($($format:tt)*) => (let _ = write!(out,$($format)*););}
    input! {
        t: usize,
        plr: [(i32, i32, i32); t],
    }
    const W: usize = 400_100;
    let mut fac = vec![0; W];
    for i in 2..W {
        if fac[i] != 0 { continue; }
        fac[i] = i;
        for j in 2..(W - 1) / i + 1 {
            fac[i * j] = i;
        }
    }
    let mut acc = vec![0; W];
    for i in 2..W {
        let mut me = 0;
        let mut v = i;
        let mut f = vec![];
        while v > 1 {
            let p = fac[v];
            let mut e = 0;
            while v % p == 0 {
                v /= p;
                e += 1;
            }
            f.push(e);
        }
        if f.len() >= 3 {
            me = 1;
        }
        if f.len() == 2 && f[0] + f[1] >= 3 {
            me = 1;
        }
        if f.len() == 1 && f[0] >= 4 {
            me = 1;
        }
        acc[i] = acc[i - 1] + me;
    }
    let lower = |x: i32| {
        if x >= 0 {
            1 + acc[x as usize]
        } else {
            -acc[(-x - 1) as usize]
        }
    };
    for (p, l, r) in plr {
        puts!("{}\n", lower(r - p) - lower(l - p - 1));
    }
}
0