結果
| 問題 | No.1200 お菓子配り-3 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-05-04 23:01:41 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 1,174 ms / 4,000 ms |
| コード長 | 1,515 bytes |
| コンパイル時間 | 13,488 ms |
| コンパイル使用メモリ | 404,640 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-22 12:33:55 |
| 合計ジャッジ時間 | 24,155 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 31 |
ソースコード
use std::collections::HashSet;
fn main() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).ok();
let s: usize = s.trim().parse().unwrap();
let queries = (0..s).map(|_| {
let mut temp = String::new();
std::io::stdin().read_line(&mut temp).ok();
let temp: Vec<usize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
let x = temp[0];
let y = temp[1];
(x.max(y), x.min(y))
})
.collect::<Vec<_>>();
for &(x, y) in queries.iter() {
let mut factors = HashSet::new();
let mut i = 2;
while i*i <= x+y {
if (x+y) % i == 0 {
factors.insert(i);
let val = (x+y) / i;
factors.insert(val);
}
i += 1;
}
let mut result = 0usize;
for &p in factors.iter() {
if x == y {
if p == 1 {
continue;
}
if p == 2 {
result += (x+y) / 2 - 1;
} else if (x+y) / p % 2 == 0 {
result += 1;
}
continue;
}
if p >= 3 && (x-y) % (p-2) == 0 {
let ax = (x+y) / p;
let bx = (x-y) / (p-2);
if ax > bx && (ax + bx) % 2 == 0{
result += 1;
}
}
}
println!("{}", result);
}
}