結果

問題 No.2767 Add to Divide
ユーザー Sai Srinivas ASai Srinivas A
提出日時 2024-05-31 21:58:46
言語 Rust
(1.77.0 + proconio)
結果
TLE  
実行時間 -
コード長 843 bytes
コンパイル時間 12,945 ms
コンパイル使用メモリ 401,176 KB
実行使用メモリ 8,992 KB
最終ジャッジ日時 2024-05-31 21:59:03
合計ジャッジ時間 16,772 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,736 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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::cmp::max`
 --> src/main.rs:1:5
  |
1 | use std::cmp::max;
  |     ^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: variable `INPUT` should have a snake case name
 --> src/main.rs:6:13
  |
6 |     let mut INPUT = io::BufReader::new(io::stdin().lock()).lines().map(Result::unwrap);
  |             ^^^^^ help: convert the identifier to snake case: `input`
  |
  = note: `#[warn(non_snake_case)]` on by default

warning: variable `OUTPUT` should have a snake case name
 --> src/main.rs:7:13
  |
7 |     let mut OUTPUT = io::BufWriter::new(io::stdout().lock());
  |             ^^^^^^ help: convert the identifier to snake case: `output`

ソースコード

diff #

use std::cmp::max;
use std::io;
use std::io::{Write, BufRead};

pub fn main(){
    let mut INPUT = io::BufReader::new(io::stdin().lock()).lines().map(Result::unwrap);
    let mut OUTPUT = io::BufWriter::new(io::stdout().lock());
    let test_cases:u32 = INPUT.next().unwrap().parse().unwrap();

   for _ in 0..test_cases{
    let inp = INPUT.next().unwrap();
    let mut inpit = inp.split_ascii_whitespace();
    let a:u32 = inpit.next().unwrap().parse().unwrap();
    let b:u32 = inpit.next().unwrap().parse().unwrap();

    let mut x = None;

    if a == b{x = Some(0);}

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

    match x {
        None => writeln!(OUTPUT, "-1").unwrap(),
        Some(x) => writeln!(OUTPUT, "{}", x).unwrap()
    }

   }
}
0