結果

問題 No.186 中華風 (Easy)
ユーザー chiho_miyakochiho_miyako
提出日時 2015-04-20 00:34:37
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,309 bytes
コンパイル時間 4,524 ms
コンパイル使用メモリ 74,816 KB
実行使用メモリ 56,256 KB
最終ジャッジ日時 2023-09-17 22:25:18
合計ジャッジ時間 8,639 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
56,168 KB
testcase_01 AC 141 ms
55,916 KB
testcase_02 AC 136 ms
55,956 KB
testcase_03 AC 126 ms
53,660 KB
testcase_04 AC 150 ms
55,672 KB
testcase_05 AC 149 ms
55,876 KB
testcase_06 AC 153 ms
56,256 KB
testcase_07 AC 147 ms
55,724 KB
testcase_08 AC 154 ms
55,948 KB
testcase_09 AC 151 ms
55,796 KB
testcase_10 AC 143 ms
55,768 KB
testcase_11 AC 157 ms
55,860 KB
testcase_12 AC 139 ms
55,972 KB
testcase_13 AC 141 ms
55,896 KB
testcase_14 AC 142 ms
56,024 KB
testcase_15 AC 131 ms
56,088 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 134 ms
56,156 KB
testcase_19 AC 124 ms
55,788 KB
testcase_20 AC 130 ms
56,100 KB
testcase_21 AC 137 ms
55,736 KB
testcase_22 AC 128 ms
55,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner koko = new Scanner(System.in);
        long[] x = new long[3];
        long[] y = new long[3];
        for(int i=0; i<3; i++){
            x[i]=koko.nextInt();
            y[i]=koko.nextInt();
        }
        long koubai = y[0]*y[1]/gcd(y[0],y[1]);
        long kouho = 0;
        long kuri = koubai/y[0];
        boolean ichi = false;
        for(long i=0; i<kuri+1; i++){
            long a = x[0]+i*y[0];
            if(a%y[1]==x[1]){
                kouho=a;
                ichi = true;
                break;
            }
        }
        if(!ichi){
            System.out.println(-1);
        }else{
            boolean flag = false;
            long koubaibai = koubai*y[2]/gcd(koubai,y[2]);
            long kurikuri = koubaibai/koubai;
            for(long i=0; i<kurikuri+1; i++){
                long b = kouho + i*koubai;
                if(b%y[2]==x[2]){
                    System.out.println(b);
                    flag=true;
                    break;
                }
            }
            if(!flag){
            System.out.println(-1);
            }
        
        }
    }
    static long gcd(long a, long b){
        return a == 0 ? b : gcd(b%a, a);
    }
}
0