結果
| 問題 |
No.186 中華風 (Easy)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-26 14:36:19 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 19 ms / 2,000 ms |
| コード長 | 1,237 bytes |
| コンパイル時間 | 11,113 ms |
| コンパイル使用メモリ | 379,060 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-19 18:38:44 |
| 合計ジャッジ時間 | 12,258 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
use std::io::*;
fn gcd(a: u64, b: u64) -> u64 {
if b == 0 {
return a;
}
gcd(b, a % b)
}
fn lcm(a: u64, b: u64) -> u64 {
a / gcd(a, b) * b
}
fn main() {
let mut s: String = String::new();
std::io::stdin().read_to_string(&mut s).ok();
let mut itr = s.trim().split_whitespace();
let mut x = vec![0u64; 3];
let mut y = vec![0u64; 3];
for i in 0..3 {
x[i] = itr.next().unwrap().parse().unwrap();
y[i] = itr.next().unwrap().parse().unwrap();
}
let mut n = 0;
let mut found = false;
for i in 0..y[1] {
n = y[0] * i + x[0];
if n % y[1] == x[1] {
found = true;
break;
}
}
if found {
let y01 = lcm(y[0], y[1]);
let mut m = 0;
found = false;
for i in 0..y[2] {
m = n + y01 * i;
if m % y[2] == x[2] {
found = true;
break;
}
}
if found {
println!(
"{}",
if m == 0 {
lcm(y[0], lcm(y[1], y[2]))
} else {
m
}
);
return;
}
}
println!("-1");
}