結果
問題 | No.2128 Round up!! |
ユーザー |
|
提出日時 | 2023-07-08 00:40:02 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,355 bytes |
コンパイル時間 | 13,162 ms |
コンパイル使用メモリ | 384,052 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-21 21:00:53 |
合計ジャッジ時間 | 15,635 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 5 WA * 7 |
ソースコード
use std::io::Read;fn get_word() -> String {let stdin = std::io::stdin();let mut stdin=stdin.lock();let mut u8b: [u8; 1] = [0];loop {let mut buf: Vec<u8> = Vec::with_capacity(16);loop {let res = stdin.read(&mut u8b);if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {break;} else {buf.push(u8b[0]);}}if buf.len() >= 1 {let ret = String::from_utf8(buf).unwrap();return ret;}}}fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }fn gcd(mut x: i64, mut y: i64) -> i64 {while y != 0 {let r = x % y;x = y;y = r;}x}fn calc(x: i64, a: i64, b: i64) -> i64 {assert!(a <= b);let g = gcd(a, b);let l = a / g * b;let ma = (x + a - 1) / a * a;let mb = (x + b - 1) / b * b;let ml = (x + l - 1) / l * l;if ma >= mb {return (ml - mb) / b * 2 + 1 + if mb == x { 0 } else { 1 };}(ml - mb) / b * 2 + 2 + if ma == x { 0 } else { 1 }}fn main() {let t: usize = get();for _ in 0..t {let x: i64 = get();let a: i64 = get();let b: i64 = get();println!("{}", if a < b { calc(x, a, b) } else { calc(x, b, a) } % 998_244_353);}}