結果

問題 No.186 中華風 (Easy)
ユーザー htensaihtensai
提出日時 2020-02-10 15:27:13
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 957 bytes
コンパイル時間 3,066 ms
コンパイル使用メモリ 77,392 KB
実行使用メモリ 57,924 KB
最終ジャッジ日時 2024-04-08 13:01:37
合計ジャッジ時間 7,730 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 177 ms
57,688 KB
testcase_01 AC 158 ms
57,704 KB
testcase_02 AC 155 ms
57,688 KB
testcase_03 AC 149 ms
57,700 KB
testcase_04 AC 173 ms
57,924 KB
testcase_05 AC 181 ms
57,780 KB
testcase_06 AC 179 ms
55,744 KB
testcase_07 AC 181 ms
57,812 KB
testcase_08 AC 188 ms
57,804 KB
testcase_09 AC 174 ms
57,792 KB
testcase_10 AC 185 ms
57,808 KB
testcase_11 AC 178 ms
57,792 KB
testcase_12 AC 165 ms
55,772 KB
testcase_13 AC 169 ms
57,828 KB
testcase_14 AC 163 ms
57,800 KB
testcase_15 AC 147 ms
57,680 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 158 ms
57,788 KB
testcase_19 AC 162 ms
57,696 KB
testcase_20 AC 164 ms
57,868 KB
testcase_21 AC 162 ms
57,784 KB
testcase_22 AC 173 ms
57,776 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();
		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