結果

問題 No.2767 Add to Divide
ユーザー atcoder8atcoder8
提出日時 2024-05-31 22:10:24
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 507 bytes
コンパイル時間 12,500 ms
コンパイル使用メモリ 393,164 KB
実行使用メモリ 13,756 KB
最終ジャッジ日時 2024-05-31 22:10:41
合計ジャッジ時間 16,199 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,756 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

use proconio::input;

fn main() {
    input! {
        t: usize,
        ab: [(usize, usize); t],
    }

    for &(a, b) in &ab {
        match solve(a, b) {
            Some(min_x) => println!("{}", min_x),
            None => println!("-1"),
        }
    }
}

fn solve(a: usize, b: usize) -> Option<usize> {
    if a == b {
        return Some(0);
    }

    for k in (2..=b / a).rev() {
        if (b - a * k) % (k - 1) == 0 {
            return Some((b - a * k) / (k - 1));
        }
    }

    None
}
0