結果

問題 No.1498 Factorization from -1 to 1
ユーザー tentententen
提出日時 2021-05-07 02:12:57
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,015 bytes
コンパイル時間 2,118 ms
コンパイル使用メモリ 75,584 KB
実行使用メモリ 61,608 KB
最終ジャッジ日時 2023-10-12 17:58:44
合計ジャッジ時間 7,330 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
54,880 KB
testcase_01 AC 56 ms
50,488 KB
testcase_02 WA -
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        boolean[] isNotPrime = new boolean[100002];
        ArrayList<Integer> primes = new ArrayList<>();
        for (int i = 2; i < isNotPrime.length; i++) {
            if (!isNotPrime[i]) {
                primes.add(i);
                for (int j = 2; i * j < isNotPrime.length; j++) {
                    isNotPrime[i * j] = true;
                }
            }
        }
        int q = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            long x = sc.nextInt();
            x = x * x + 1;
            boolean isFirst = true;
            for (int y : primes) {
                if (y > Math.sqrt(x)) {
                    break;
                }
                if (x % y == 0) {
                    if (!isFirst) {
                        sb.append(" ");
                    }
                    isFirst = false;
                    sb.append(y);
                    while (x % y == 0) {
                        x /= y;
                    }
                }
            }
            if (x > 1) {
                if (!isFirst) {
                    sb.append(" ");
                }
                sb.append(x);
            }
            sb.append("\n");
        }
        System.out.print(sb);
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0