結果

問題 No.1200 お菓子配り-3
ユーザー 箱星箱星
提出日時 2020-08-28 22:16:21
言語 Rust
(1.77.0 + proconio)
結果
AC  
実行時間 1,520 ms / 4,000 ms
コード長 2,205 bytes
コンパイル時間 12,485 ms
コンパイル使用メモリ 382,932 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-30 23:46:53
合計ジャッジ時間 26,629 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 11 ms
6,944 KB
testcase_08 AC 12 ms
6,944 KB
testcase_09 AC 11 ms
6,940 KB
testcase_10 AC 11 ms
6,940 KB
testcase_11 AC 11 ms
6,944 KB
testcase_12 AC 98 ms
6,944 KB
testcase_13 AC 101 ms
6,944 KB
testcase_14 AC 98 ms
6,940 KB
testcase_15 AC 98 ms
6,940 KB
testcase_16 AC 106 ms
6,944 KB
testcase_17 AC 363 ms
6,944 KB
testcase_18 AC 537 ms
6,940 KB
testcase_19 AC 133 ms
6,940 KB
testcase_20 AC 983 ms
6,940 KB
testcase_21 AC 1,015 ms
6,940 KB
testcase_22 AC 1,159 ms
6,940 KB
testcase_23 AC 977 ms
6,940 KB
testcase_24 AC 963 ms
6,940 KB
testcase_25 AC 967 ms
6,940 KB
testcase_26 AC 983 ms
6,940 KB
testcase_27 AC 0 ms
6,940 KB
testcase_28 AC 1,297 ms
6,944 KB
testcase_29 AC 1,520 ms
6,944 KB
testcase_30 AC 1,505 ms
6,944 KB
testcase_31 AC 1 ms
6,944 KB
testcase_32 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::{stdout, BufWriter, Write};
use std::io;

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    n.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    n.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let out = stdout();
    let mut writer = BufWriter::new(out.lock());
    solve(&mut writer);
    writer.flush().unwrap();
}

fn solve<W: Write>(mut writer: W) {
    #[allow(unused_macros)]
    macro_rules! print {
        ($fmt:expr) => {
            write!(writer, $fmt).unwrap()
        };
        ($fmt:expr, $($arg:tt)*) => {
            write!(writer, $fmt, $($arg)*).unwrap()
        };
    }
    #[allow(unused_macros)]
    macro_rules! println {
        ($fmt:expr) => {
            writeln!(writer, $fmt).unwrap()
        };
        ($fmt:expr, $($arg:tt)*) => {
            writeln!(writer, $fmt, $($arg)*).unwrap()
        };
    }

    // Main Code
    let s: usize = read();
    for _ in 0..s {
        let data = read_vec::<usize>();
        let x = data[0];
        let y = data[1];
        let mut cand_a = std::collections::HashSet::new();
        let n1 = x + y;
        let mut d: usize = 1;
        while d * d <= n1 {
            if n1 % d == 0 {
                cand_a.insert(d - 1);
                cand_a.insert(n1 / d - 1);
            }
            d += 1;
        }
        let n2 = if x > y { x - y } else { y - x };
        d = 1;
        while d * d <= n2 {
            if n2 % d == 0 {
                cand_a.insert(d + 1);
                cand_a.insert(n2 / d + 1);
            }
            d += 1;
        }
        let mut ans = 0;
        cand_a.remove(&0);
        cand_a.remove(&1);
        for a in cand_a {
            let num = a * a - 1;
            if a * x > y && a * y > x && (a * x - y) % num == 0 && (a * y - x) % num == 0 {
                ans += 1;
            }
        }
        if x == y {
            ans += x - 1;
        }
        println!("{}", ans);
    }
}
0