結果
| 問題 | No.186 中華風 (Easy) |
| コンテスト | |
| ユーザー |
htensai
|
| 提出日時 | 2020-02-10 15:32:28 |
| 言語 | Java (openjdk 25.0.2) |
| 結果 |
AC
|
| 実行時間 | 90 ms / 2,000 ms |
| + 703µs | |
| コード長 | 1,062 bytes |
| 記録 | |
| コンパイル時間 | 1,352 ms |
| コンパイル使用メモリ | 84,516 KB |
| 実行使用メモリ | 45,188 KB |
| 最終ジャッジ日時 | 2026-08-18 21:39:43 |
| 合計ジャッジ時間 | 4,521 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
import java.util.*;
public class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int x1 = sc.nextInt();
long y1 = sc.nextInt();
int x2 = sc.nextInt();
int y2 = sc.nextInt();
int x3 = sc.nextInt();
int y3 = sc.nextInt();
if (x1 == 0 && x2 == 0 && x3 == 0) {
System.out.println(lcm(lcm(y1, y2), y3));
return;
}
long ans = 0;
for (int i = 0; i < 1000000; i++) {
ans = y1 * i + x1;
if (ans % y2 == x2) {
break;
}
}
if (ans % y2 != x2) {
System.out.println(-1);
return;
}
long y1y2 = lcm(y1, y2);
long fine = 0;
for (int i = 0; i < 1000000; i++) {
fine = y1y2 * i + ans;
if (fine % y3 == x3) {
System.out.println(fine);
return;
}
}
System.out.println(-1);
}
static long lcm(long x, long y) {
return x / gcd(x, y) * y;
}
static long gcd(long x, long y) {
if (x % y == 0) {
return y;
} else {
return gcd(y, x % y);
}
}
}
htensai