結果

問題 No.2519 Coins in Array
ユーザー ks2mks2m
提出日時 2023-10-27 22:50:32
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,668 bytes
コンパイル時間 2,512 ms
コンパイル使用メモリ 80,592 KB
実行使用メモリ 76,044 KB
最終ジャッジ日時 2023-10-27 22:50:47
合計ジャッジ時間 14,559 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 AC 60 ms
54,316 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 71 ms
54,312 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 62 ms
54,316 KB
testcase_20 AC 65 ms
54,320 KB
testcase_21 AC 65 ms
54,340 KB
testcase_22 RE -
testcase_23 AC 441 ms
75,740 KB
testcase_24 WA -
testcase_25 AC 61 ms
54,308 KB
testcase_26 AC 61 ms
54,340 KB
testcase_27 AC 488 ms
76,004 KB
testcase_28 AC 479 ms
76,044 KB
testcase_29 WA -
testcase_30 AC 428 ms
73,344 KB
testcase_31 AC 218 ms
59,900 KB
testcase_32 AC 326 ms
63,920 KB
testcase_33 AC 395 ms
67,240 KB
testcase_34 AC 284 ms
61,916 KB
testcase_35 WA -
testcase_36 AC 246 ms
62,372 KB
testcase_37 WA -
testcase_38 AC 351 ms
66,324 KB
testcase_39 AC 258 ms
61,828 KB
testcase_40 AC 472 ms
75,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		if (n >= 4) {
			PrintWriter pw = new PrintWriter(System.out);
			pw.println(0);
			pw.println("1 2");
			pw.println("1 2");
			for (int i = n - 2; i >= 2; i--) {
				pw.println("1 " + i);
			}
			pw.flush();

		} else {
			Set<Integer> set = new HashSet<>();
			Map<Integer, Integer> map0 = bunkai(a[0]);
			for (Integer k : map0.keySet()) {
				set.add(k);
			}
			long m = a[0];
			for (int i = 1; i < n; i++) {
				Map<Integer, Integer> map = bunkai(a[i]);
				for (Integer k : map.keySet()) {
					if (!set.add(k)) {
						m = 0;
						break;
					}
				}
				if (m != 0) {
					m = (m - 1) * (a[i] - 1);
				}
			}
			System.out.println(m);
			for (int i = 0; i < n - 1; i++) {
				System.out.println("1 2");
			}
			throw new RuntimeException();
		}
	}

	static Map<Integer, Integer> bunkai(int n) {
		Map<Integer, Integer> soinsu = new HashMap<>();
		int end = (int) Math.sqrt(n);
		int d = 2;
		while (n > 1) {
			if (n % d == 0) {
				n /= d;
				soinsu.put(d, soinsu.getOrDefault(d, 0) + 1);
				end = (int) Math.sqrt(n);
			} else {
				if (d > end) {
					d = n - 1;
				}
				d++;
			}
		}
		return soinsu;
	}
}
0