結果
問題 | No.2074 Product is Square ? |
ユーザー | tenten |
提出日時 | 2023-04-13 17:01:02 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 713 ms / 2,000 ms |
コード長 | 2,729 bytes |
コンパイル時間 | 2,960 ms |
コンパイル使用メモリ | 84,864 KB |
実行使用メモリ | 44,728 KB |
最終ジャッジ日時 | 2024-10-09 14:20:01 |
合計ジャッジ時間 | 12,893 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
36,916 KB |
testcase_01 | AC | 102 ms
39,132 KB |
testcase_02 | AC | 91 ms
39,316 KB |
testcase_03 | AC | 103 ms
39,008 KB |
testcase_04 | AC | 103 ms
39,328 KB |
testcase_05 | AC | 104 ms
39,276 KB |
testcase_06 | AC | 103 ms
39,232 KB |
testcase_07 | AC | 105 ms
38,860 KB |
testcase_08 | AC | 103 ms
39,268 KB |
testcase_09 | AC | 102 ms
39,132 KB |
testcase_10 | AC | 105 ms
39,260 KB |
testcase_11 | AC | 249 ms
44,416 KB |
testcase_12 | AC | 334 ms
44,524 KB |
testcase_13 | AC | 706 ms
44,592 KB |
testcase_14 | AC | 348 ms
44,472 KB |
testcase_15 | AC | 250 ms
44,476 KB |
testcase_16 | AC | 350 ms
44,568 KB |
testcase_17 | AC | 711 ms
44,548 KB |
testcase_18 | AC | 344 ms
44,588 KB |
testcase_19 | AC | 239 ms
44,512 KB |
testcase_20 | AC | 310 ms
44,384 KB |
testcase_21 | AC | 713 ms
44,388 KB |
testcase_22 | AC | 324 ms
44,716 KB |
testcase_23 | AC | 235 ms
44,728 KB |
testcase_24 | AC | 339 ms
44,432 KB |
testcase_25 | AC | 552 ms
44,680 KB |
testcase_26 | AC | 297 ms
44,656 KB |
testcase_27 | AC | 252 ms
44,676 KB |
testcase_28 | AC | 344 ms
44,672 KB |
testcase_29 | AC | 500 ms
44,664 KB |
testcase_30 | AC | 298 ms
44,504 KB |
testcase_31 | AC | 57 ms
37,428 KB |
testcase_32 | AC | 54 ms
37,156 KB |
testcase_33 | AC | 82 ms
38,736 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int t = sc.nextInt(); StringBuilder sb = new StringBuilder(); while (t-- > 0) { int n = sc.nextInt(); long[] values = new long[n]; for (int i = 0; i < n; i++) { values[i] = sc.nextLong(); } boolean enable = true; for (int i = 0; i < n && enable; i++) { for (int j = i + 1; j < n; j++) { long gcd = getGCD(values[i], values[j]); values[i] /= gcd; values[j] /= gcd; } enable = isSquare(values[i]); } if (enable) { sb.append("Yes\n"); } else { sb.append("No\n"); } } System.out.print(sb); } static long getGCD(long x, long y) { if (y == 0) { return x; } else { return getGCD(y, x % y); } } static boolean isSquare(long x) { long left = 0; long right = Integer.MAX_VALUE / 2; while (right - left > 1) { long m = (left + right) / 2; if (m * m <= x) { left = m; } else { right = m; } } return left * left == x; } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }