結果
問題 |
No.186 中華風 (Easy)
|
ユーザー |
![]() |
提出日時 | 2020-02-10 15:32:28 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 163 ms / 2,000 ms |
コード長 | 1,062 bytes |
コンパイル時間 | 2,797 ms |
コンパイル使用メモリ | 77,268 KB |
実行使用メモリ | 41,520 KB |
最終ジャッジ日時 | 2024-07-19 18:37:54 |
合計ジャッジ時間 | 6,662 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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); } } }