結果
問題 |
No.186 中華風 (Easy)
|
ユーザー |
![]() |
提出日時 | 2020-02-10 15:27:13 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 957 bytes |
コンパイル時間 | 1,757 ms |
コンパイル使用メモリ | 77,112 KB |
実行使用メモリ | 41,588 KB |
最終ジャッジ日時 | 2024-10-01 06:24:47 |
合計ジャッジ時間 | 5,371 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 WA * 2 |
ソースコード
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(); 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); } } }