結果

問題 No.2526 Kth Not-divisible Number
ユーザー tttttaaatttttaaa
提出日時 2023-11-03 21:44:42
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 2,994 bytes
コンパイル時間 1,037 ms
コンパイル使用メモリ 178,928 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-11-03 21:44:48
合計ジャッジ時間 4,730 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 WA -
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 262 ms
4,348 KB
testcase_04 AC 259 ms
4,348 KB
testcase_05 AC 263 ms
4,348 KB
testcase_06 AC 264 ms
4,348 KB
testcase_07 AC 267 ms
4,348 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 138 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unnecessary parentheses around `while` condition
  --> Main.rs:42:11
   |
42 |     while (l + 1 < r) {
   |           ^         ^
   |
   = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
   |
42 -     while (l + 1 < r) {
42 +     while l + 1 < r {
   |

warning: 1 warning emitted

ソースコード

diff #

#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(non_snake_case)]

pub use __cargo_equip::prelude::*;

use kyopro_io::get;
use std::io::{StdoutLock, Write};

const JU_5: usize = 100_000;
const JU_9: usize = JU_5 * 10_000;
const JU_18: usize = JU_9 * JU_9;
const INF: usize = JU_9 + 100_100;
const INFL: usize = JU_18 * 2;

const MULTIPLE_TEST_CASE: bool = true;

fn gcd(a: usize, b: usize) -> usize {
    if a > b {
        return gcd(b, a);
    }
    if a == 0 {
        return b;
    }
    gcd(b % a, a)
}
fn lcm(a: usize, b: usize) -> usize {
    let g = gcd(a, b);
    (a / g) * (b / g) * g
}

fn _main(writer: &mut std::io::BufWriter<StdoutLock>) {
    let (a, b, k) = get!(usize, usize, usize);
    let L = lcm(a, b);
    let mut l = 0;
    let mut r = INFL;
    let _f = |m: usize| {
        let x = m / a + m / b - m / L;
        return (m - x) < k;
    };
    while (l + 1 < r) {
        let m = (l + r) / 2;
        if _f(m) {
            l = m;
        } else {
            r = m;
        }
    }
    writeln!(writer, "{}", r).unwrap();
}
// writeln!(writer, "{}", ans).unwrap();

fn main() {
    let t = if MULTIPLE_TEST_CASE { get!(usize) } else { 1 };

    let stdout = std::io::stdout();
    let mut writer = std::io::BufWriter::new(stdout.lock());

    for _ in 0..t {
        _main(&mut writer);
    }
}

// The following code was expanded by `cargo-equip`.

///  # Bundled libraries
/// 
///  - `kyopro-io 0.1.0 (path+████████████████████████████████████████████████)` published in **missing** licensed under `CC0-1.0` as `crate::__cargo_equip::crates::kyopro_io`
#[cfg_attr(any(), rustfmt::skip)]
#[allow(unused)]
mod __cargo_equip {
    pub(crate) mod crates {
        pub mod kyopro_io {pub use crate::__cargo_equip::macros::kyopro_io::*;#[macro_export]macro_rules!__cargo_equip_macro_def_kyopro_io_get{($t:ty)=>{{let mut line:String=String::new();std::io::stdin().read_line(&mut line).unwrap();line.trim().parse::<$t>().unwrap()}};($($t:ty),*)=>{{let mut line:String=String::new();std::io::stdin().read_line(&mut line).unwrap();let mut iter=line.split_whitespace();($(iter.next().unwrap().parse::<$t>().unwrap(),)*)}};($t:ty;$n:expr)=>{(0..$n).map(|_|get!($t)).collect::<Vec<_>>()};($($t:ty),*;$n:expr)=>{(0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()};($t:ty;;)=>{{let mut line:String=String::new();std::io::stdin().read_line(&mut line).unwrap();line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()}};($t:ty;;$n:expr)=>{(0..$n).map(|_|get!($t;;)).collect::<Vec<_>>()};}macro_rules!get{($($tt:tt)*)=>(crate::__cargo_equip_macro_def_kyopro_io_get!{$($tt)*})}}
    }

    pub(crate) mod macros {
        pub mod kyopro_io {pub use crate::__cargo_equip_macro_def_kyopro_io_get as get;}
    }

    pub(crate) mod prelude {pub use crate::__cargo_equip::crates::*;}

    mod preludes {
        pub mod kyopro_io {}
    }
}
0