結果

問題 No.2767 Add to Divide
ユーザー maguroflymagurofly
提出日時 2024-06-01 10:29:56
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 508 bytes
コンパイル時間 12,936 ms
コンパイル使用メモリ 398,412 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-01 10:30:12
合計ジャッジ時間 14,440 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 13 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 8 ms
6,940 KB
testcase_06 WA -
testcase_07 AC 9 ms
6,944 KB
testcase_08 AC 11 ms
6,940 KB
testcase_09 WA -
testcase_10 AC 10 ms
6,940 KB
testcase_11 AC 10 ms
6,944 KB
testcase_12 AC 10 ms
6,944 KB
testcase_13 AC 10 ms
6,940 KB
testcase_14 AC 10 ms
6,940 KB
testcase_15 AC 10 ms
6,940 KB
testcase_16 AC 10 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable `T` should have a snake case name
  --> src/main.rs:20:9
   |
20 |     input!(T: usize);
   |            ^ help: convert the identifier to snake case: `t`
   |
   = note: `#[warn(non_snake_case)]` on by default

warning: variable `A` should have a snake case name
  --> src/main.rs:22:10
   |
22 |         input!(A: usize, B: usize);
   |                ^ help: convert the identifier to snake case: `a`

warning: variable `B` should have a snake case name
  --> src/main.rs:22:20
   |
22 |         input!(A: usize, B: usize);
   |                          ^ help: convert the identifier to snake case: `b`

ソースコード

diff #

use proconio::input;

fn divisors(n: usize) -> Vec<usize> {
	let mut ds = vec![];
	let mut k = 1;
	while k * k < n {
		if n % k == 0 {
			ds.push(k);
			ds.push(n / k);
		}
		k += 1;	
	}
	if k * k == n {
		ds.push(k);
	}
	ds
}

fn main() {
	input!(T: usize);
	for _ in 0 .. T {
		input!(A: usize, B: usize);
		if let Some(ans) = divisors(B - A).into_iter().filter_map(|d| if B >= A * (d + 1) { Some((B - A * (d + 1)) / d) } else { None } ).min() {
			println!("{ans}");
		} else {
			println!("-1");
		}
	}
}
0