結果

問題 No.186 中華風 (Easy)
ユーザー chiho_miyakochiho_miyako
提出日時 2015-04-20 00:37:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 1,314 bytes
コンパイル時間 2,519 ms
コンパイル使用メモリ 73,488 KB
実行使用メモリ 56,244 KB
最終ジャッジ日時 2023-09-27 00:44:43
合計ジャッジ時間 6,829 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
55,692 KB
testcase_01 AC 136 ms
56,056 KB
testcase_02 AC 133 ms
55,828 KB
testcase_03 AC 121 ms
55,892 KB
testcase_04 AC 144 ms
56,164 KB
testcase_05 AC 145 ms
55,876 KB
testcase_06 AC 148 ms
56,244 KB
testcase_07 AC 143 ms
55,836 KB
testcase_08 AC 154 ms
55,684 KB
testcase_09 AC 152 ms
55,668 KB
testcase_10 AC 140 ms
55,788 KB
testcase_11 AC 154 ms
56,068 KB
testcase_12 AC 141 ms
55,824 KB
testcase_13 AC 139 ms
55,904 KB
testcase_14 AC 142 ms
56,028 KB
testcase_15 AC 130 ms
55,460 KB
testcase_16 AC 136 ms
55,832 KB
testcase_17 AC 123 ms
56,232 KB
testcase_18 AC 138 ms
55,724 KB
testcase_19 AC 122 ms
55,824 KB
testcase_20 AC 129 ms
55,944 KB
testcase_21 AC 139 ms
55,768 KB
testcase_22 AC 128 ms
55,704 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]&&b>0){
                    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