結果

問題 No.854 公平なりんご分配
ユーザー tentententen
提出日時 2020-12-16 10:05:38
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,590 bytes
コンパイル時間 3,348 ms
コンパイル使用メモリ 77,292 KB
実行使用メモリ 261,028 KB
最終ジャッジ日時 2023-10-20 09:04:44
合計ジャッジ時間 55,486 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
57,392 KB
testcase_01 AC 128 ms
57,516 KB
testcase_02 WA -
testcase_03 AC 132 ms
57,588 KB
testcase_04 AC 132 ms
57,396 KB
testcase_05 AC 131 ms
57,532 KB
testcase_06 AC 132 ms
57,476 KB
testcase_07 WA -
testcase_08 AC 135 ms
57,604 KB
testcase_09 AC 129 ms
57,404 KB
testcase_10 AC 131 ms
57,500 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 135 ms
57,480 KB
testcase_15 AC 136 ms
57,612 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 137 ms
57,732 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 WA -
testcase_83 AC 1,617 ms
259,540 KB
testcase_84 WA -
testcase_85 AC 1,558 ms
258,200 KB
testcase_86 AC 1,200 ms
256,548 KB
testcase_87 WA -
testcase_88 WA -
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
testcase_92 WA -
testcase_93 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean[] isNotPrime = new boolean[2000];
		int size = 0;
		for (int i = 2; i < 2000; i++) {
		    if (!isNotPrime[i]) {
		        size++;
		        for (int j = 2; j * i < 2000; j++) {
		            isNotPrime[j * i] = true;
		        }
		    }
		}
		int[] primes = new int[size];
		int idx = 0;
		for (int i = 2; i < 2000; i++) {
		    if (!isNotPrime[i]) {
		        primes[idx] = i;
		        idx++;
		    }
		}
		int[][] counts = new int[n + 1][];
		counts[0] = new int[size];
		for (int i = 0; i < n; i++) {
		    int x = sc.nextInt();
		    counts[i + 1] = (int[])counts[i].clone();
		    for (int j = 0; j < size && x > 1; j++) {
		        while (x % primes[j] == 0) {
		            counts[i + 1][j]++;
		            x /= primes[j];
		        }
		    }
		}
		int q = sc.nextInt();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
		    int p = sc.nextInt();
		    int left = sc.nextInt() - 1;
		    int right = sc.nextInt();
		    for (int j = 0; j < size && p > 1 && p % primes[j] == 0; j++) {
		        int limit = counts[right][j] - counts[left][j];
		        for (int k = 0; k < limit; k++) {
		            if (p % primes[j] == 0) {
		                p /= primes[j];
		            } else {
		                break;
		            }
		        }
		    }
		    if (p == 1) {
		        sb.append("Yes");
		    } else {
		        sb.append("NO");
		    }
		    sb.append("\n");
		}
		System.out.print(sb);
	}
}
0