結果

問題 No.1200 お菓子配り-3
ユーザー StrorkisStrorkis
提出日時 2020-08-29 16:45:46
言語 Rust
(1.77.0)
結果
AC  
実行時間 1,153 ms / 4,000 ms
コード長 1,549 bytes
コンパイル時間 12,853 ms
コンパイル使用メモリ 384,740 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-01 00:10:33
合計ジャッジ時間 23,023 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
6,816 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 AC 1 ms
6,812 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 8 ms
6,944 KB
testcase_08 AC 8 ms
6,940 KB
testcase_09 AC 8 ms
6,944 KB
testcase_10 AC 8 ms
6,944 KB
testcase_11 AC 8 ms
6,940 KB
testcase_12 AC 69 ms
6,944 KB
testcase_13 AC 70 ms
6,944 KB
testcase_14 AC 72 ms
6,940 KB
testcase_15 AC 71 ms
6,940 KB
testcase_16 AC 70 ms
6,944 KB
testcase_17 AC 248 ms
6,940 KB
testcase_18 AC 356 ms
6,944 KB
testcase_19 AC 84 ms
6,940 KB
testcase_20 AC 694 ms
6,948 KB
testcase_21 AC 697 ms
6,940 KB
testcase_22 AC 826 ms
6,944 KB
testcase_23 AC 689 ms
6,944 KB
testcase_24 AC 692 ms
6,940 KB
testcase_25 AC 688 ms
6,940 KB
testcase_26 AC 688 ms
6,944 KB
testcase_27 AC 1 ms
6,944 KB
testcase_28 AC 1,153 ms
6,940 KB
testcase_29 AC 841 ms
6,940 KB
testcase_30 AC 846 ms
6,944 KB
testcase_31 AC 1 ms
6,944 KB
testcase_32 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Write;

fn read_line() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf
}

fn read_u() -> usize {
    let buf = read_line();
    buf.trim_end().parse().unwrap()
}

fn read_i2t() -> (i32, i32) {
    let buf = read_line();
    let mut iter = buf.split_whitespace();
    (
        iter.next().unwrap().parse().unwrap(),
        iter.next().unwrap().parse().unwrap(),
    )
}

fn main () {
    let stdout = std::io::stdout();
    let mut writer = std::io::BufWriter::new(stdout.lock());

    let s: usize = read_u();

    let get_divisors = |n: i32| -> Vec<i32> {
        let mut divisors = vec![];
        for p in 1.. {
            if p * p > n { break; }
            if n % p > 0 { continue; }
            divisors.push(p);
            if p * p == n { continue; }
            divisors.push(n / p);
        }
        divisors
    };

    for _ in 0..s {
        let (x, y): (i32, i32) = read_i2t();

        let p = x + y;
        let q = (x - y).abs();

        let mut ans = 0;
        let divisors = get_divisors(p);
        for &i in &divisors {
            if i == 1 { continue; }
            let j = p / i;
            if i == 2 {
                if q > 0 { continue; }
                ans += j - 1;
            } else if q % (i - 2) == 0 {
                let u = j;
                let v = q / (i - 2);
                if u > v && (u + v) % 2 == 0 {
                    ans += 1;
                }
            }
        }
        writeln!(writer, "{}", ans).unwrap();
    }
}
0