結果

問題 No.186 中華風 (Easy)
ユーザー htensaihtensai
提出日時 2020-02-10 15:32:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 1,062 bytes
コンパイル時間 3,021 ms
コンパイル使用メモリ 73,744 KB
実行使用メモリ 56,084 KB
最終ジャッジ日時 2023-09-27 00:58:36
合計ジャッジ時間 7,015 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
55,688 KB
testcase_01 AC 130 ms
55,604 KB
testcase_02 AC 126 ms
55,448 KB
testcase_03 AC 116 ms
55,876 KB
testcase_04 AC 136 ms
55,700 KB
testcase_05 AC 135 ms
55,920 KB
testcase_06 AC 136 ms
55,672 KB
testcase_07 AC 138 ms
55,620 KB
testcase_08 AC 144 ms
55,616 KB
testcase_09 AC 142 ms
55,688 KB
testcase_10 AC 141 ms
55,712 KB
testcase_11 AC 145 ms
55,756 KB
testcase_12 AC 127 ms
55,772 KB
testcase_13 AC 132 ms
56,084 KB
testcase_14 AC 134 ms
55,904 KB
testcase_15 AC 119 ms
55,768 KB
testcase_16 AC 118 ms
55,772 KB
testcase_17 AC 120 ms
55,856 KB
testcase_18 AC 121 ms
55,672 KB
testcase_19 AC 131 ms
55,616 KB
testcase_20 AC 132 ms
55,860 KB
testcase_21 AC 132 ms
55,660 KB
testcase_22 AC 133 ms
55,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
        }
    }
}
0