結果

問題 No.1514 Squared Matching
ユーザー tentententen
提出日時 2021-05-25 14:10:09
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,772 bytes
コンパイル時間 2,382 ms
コンパイル使用メモリ 78,124 KB
実行使用メモリ 44,192 KB
最終ジャッジ日時 2024-04-22 01:13:11
合計ジャッジ時間 7,895 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
42,412 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
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 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int size = (int)(Math.sqrt(n)) + 1;
        ArrayList<Integer> listPrimes = new ArrayList<>();
        boolean[] isNotPrime = new boolean[size];
        for (int i = 2; i < size; i++) {
            if (!isNotPrime[i]) {
                listPrimes.add(i);
                for (int j = 2; j * i < size; j++) {
                    isNotPrime[j * i] = true;
                }
            }
        }
        int length = listPrimes.size();
        int[] primes = new int[length];
        for (int i = 0; i < length; i++) {
            primes[i] = listPrimes.get(i) * listPrimes.get(i);
        }
        long ans = 0;
        for (int i = 1; i <= n; i++) {
            int x = i;
            int count = 1;
            for (int j = 0; j < length && primes[j] <= x; j++) {
                while (x % primes[j] == 0) {
                    count++;
                    x /= primes[j];
                }
            }
            ans += count * 2 - 1;
        }
        System.out.println(ans);
    }
}

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