結果

問題 No.1200 お菓子配り-3
ユーザー 👑 箱星箱星
提出日時 2020-08-28 22:26:07
言語 Rust
(1.77.0)
結果
AC  
実行時間 1,137 ms / 4,000 ms
コード長 2,150 bytes
コンパイル時間 12,221 ms
コンパイル使用メモリ 387,868 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-30 23:55:06
合計ジャッジ時間 22,169 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
6,812 KB
testcase_01 AC 0 ms
6,812 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,948 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 8 ms
6,944 KB
testcase_08 AC 7 ms
6,940 KB
testcase_09 AC 8 ms
6,944 KB
testcase_10 AC 7 ms
6,940 KB
testcase_11 AC 8 ms
6,944 KB
testcase_12 AC 67 ms
6,940 KB
testcase_13 AC 68 ms
6,944 KB
testcase_14 AC 70 ms
6,940 KB
testcase_15 AC 69 ms
6,940 KB
testcase_16 AC 72 ms
6,940 KB
testcase_17 AC 247 ms
6,940 KB
testcase_18 AC 355 ms
6,944 KB
testcase_19 AC 81 ms
6,940 KB
testcase_20 AC 675 ms
6,940 KB
testcase_21 AC 686 ms
6,940 KB
testcase_22 AC 813 ms
6,940 KB
testcase_23 AC 685 ms
6,940 KB
testcase_24 AC 681 ms
6,940 KB
testcase_25 AC 673 ms
6,944 KB
testcase_26 AC 671 ms
6,944 KB
testcase_27 AC 1 ms
6,940 KB
testcase_28 AC 1,137 ms
6,940 KB
testcase_29 AC 838 ms
6,940 KB
testcase_30 AC 820 ms
6,940 KB
testcase_31 AC 1 ms
6,940 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 n2 = if x > y { x - y } else { y - x };
        let mut d: usize = 1;
        while d * d <= n1 {
            if n1 % d == 0 {
                let a = d - 1;
                if a >= 2 && n2 % (a - 1) == 0 {
                    cand_a.insert(a);
                }
                let a = n1 / d - 1;
                if a >= 2 && n2 % (a - 1) == 0 {
                    cand_a.insert(a);
                }
            }
            d += 1;
        }
        let mut ans = 0;
        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