結果

問題 No.736 約比
ユーザー tsunabittsunabit
提出日時 2019-08-07 15:51:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 1,071 bytes
コンパイル時間 3,715 ms
コンパイル使用メモリ 71,732 KB
実行使用メモリ 56,464 KB
最終ジャッジ日時 2023-09-25 22:45:54
合計ジャッジ時間 15,341 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
55,984 KB
testcase_01 AC 136 ms
55,596 KB
testcase_02 AC 131 ms
55,548 KB
testcase_03 AC 141 ms
55,596 KB
testcase_04 AC 146 ms
55,580 KB
testcase_05 AC 124 ms
55,868 KB
testcase_06 AC 123 ms
56,256 KB
testcase_07 AC 146 ms
56,180 KB
testcase_08 AC 145 ms
56,036 KB
testcase_09 AC 138 ms
55,976 KB
testcase_10 AC 145 ms
55,992 KB
testcase_11 AC 145 ms
55,928 KB
testcase_12 AC 146 ms
56,344 KB
testcase_13 AC 143 ms
55,724 KB
testcase_14 AC 132 ms
55,416 KB
testcase_15 AC 146 ms
56,248 KB
testcase_16 AC 134 ms
56,148 KB
testcase_17 AC 142 ms
55,780 KB
testcase_18 AC 143 ms
55,836 KB
testcase_19 AC 138 ms
55,588 KB
testcase_20 AC 144 ms
56,036 KB
testcase_21 AC 143 ms
56,348 KB
testcase_22 AC 124 ms
56,280 KB
testcase_23 AC 123 ms
55,912 KB
testcase_24 AC 145 ms
56,164 KB
testcase_25 AC 123 ms
54,000 KB
testcase_26 AC 123 ms
55,924 KB
testcase_27 AC 146 ms
53,876 KB
testcase_28 AC 145 ms
55,856 KB
testcase_29 AC 121 ms
55,608 KB
testcase_30 AC 143 ms
55,724 KB
testcase_31 AC 121 ms
55,852 KB
testcase_32 AC 121 ms
55,560 KB
testcase_33 AC 140 ms
55,604 KB
testcase_34 AC 123 ms
56,116 KB
testcase_35 AC 128 ms
55,932 KB
testcase_36 AC 145 ms
55,996 KB
testcase_37 AC 144 ms
56,248 KB
testcase_38 AC 144 ms
55,616 KB
testcase_39 AC 123 ms
55,836 KB
testcase_40 AC 146 ms
56,224 KB
testcase_41 AC 145 ms
55,800 KB
testcase_42 AC 140 ms
56,112 KB
testcase_43 AC 144 ms
56,036 KB
testcase_44 AC 136 ms
55,720 KB
testcase_45 AC 142 ms
56,212 KB
testcase_46 AC 123 ms
55,556 KB
testcase_47 AC 152 ms
55,884 KB
testcase_48 AC 134 ms
56,264 KB
testcase_49 AC 127 ms
54,128 KB
testcase_50 AC 130 ms
56,416 KB
testcase_51 AC 131 ms
56,464 KB
testcase_52 AC 148 ms
55,812 KB
testcase_53 AC 142 ms
56,324 KB
testcase_54 AC 135 ms
56,124 KB
testcase_55 AC 131 ms
56,176 KB
testcase_56 AC 133 ms
53,900 KB
testcase_57 AC 125 ms
55,992 KB
testcase_58 AC 144 ms
55,976 KB
testcase_59 AC 147 ms
55,792 KB
testcase_60 AC 132 ms
56,192 KB
testcase_61 AC 144 ms
56,072 KB
testcase_62 AC 122 ms
55,740 KB
testcase_63 AC 117 ms
55,996 KB
testcase_64 AC 123 ms
56,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.math.*;

public class No736 {
    public static void main(String[] args) {
    	try {
    		// 入力元がファイルの場合
//    		 Scanner sc = new Scanner(new File("/Users/aa352872/Desktop/test"));
    		// 入力元が標準入力の場合
    		Scanner sc = new Scanner(System.in);
    		int n = sc.nextInt();
    		long a[] = new long[n];

    		for(int i = 0; i < n; i++) {
    			a[i] = sc.nextLong();
    		}
    		long gcd = a[0];
    		for (int i = 1; i < n; i++) {
    			gcd = gcd(gcd, a[i]);
    		}
    		for (int i = 0; i < n; i++) {
    			if (i > 0) {
    				System.out.print(':');
    			}
    			System.out.print(a[i] / gcd);
    		}
    		System.out.println();
    	}catch (Exception e) {
    		System.out.println("例外が発生しました。");
            System.out.println(e);
            return;
    	}
    }
    // ユークリッド互除法で最大公約数を求める
    static long gcd(long n, long m) {
		if (m == 0) {
			return n;
		} else {
			return gcd(m, n % m);
		}
	}
}
0