結果
問題 | No.1200 お菓子配り-3 |
ユーザー |
|
提出日時 | 2020-08-28 22:16:21 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 1,700 ms / 4,000 ms |
コード長 | 2,205 bytes |
コンパイル時間 | 16,555 ms |
コンパイル使用メモリ | 401,376 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-20 22:28:41 |
合計ジャッジ時間 | 29,732 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 31 |
ソースコード
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 Codelet 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);}}