結果

問題 No.1006 Share an Integer
ユーザー tentententen
提出日時 2022-10-06 08:46:56
言語 Java21
(openjdk 21)
結果
AC  
実行時間 166 ms / 2,000 ms
コード長 1,683 bytes
コンパイル時間 3,500 ms
コンパイル使用メモリ 75,232 KB
実行使用メモリ 44,788 KB
最終ジャッジ日時 2023-08-30 20:45:17
合計ジャッジ時間 7,622 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
33,564 KB
testcase_01 AC 40 ms
33,288 KB
testcase_02 AC 39 ms
33,532 KB
testcase_03 AC 39 ms
33,600 KB
testcase_04 AC 39 ms
33,328 KB
testcase_05 AC 40 ms
33,608 KB
testcase_06 AC 40 ms
33,756 KB
testcase_07 AC 40 ms
33,612 KB
testcase_08 AC 40 ms
33,352 KB
testcase_09 AC 40 ms
33,460 KB
testcase_10 AC 40 ms
33,380 KB
testcase_11 AC 109 ms
40,560 KB
testcase_12 AC 157 ms
44,104 KB
testcase_13 AC 161 ms
44,700 KB
testcase_14 AC 164 ms
44,788 KB
testcase_15 AC 147 ms
43,384 KB
testcase_16 AC 105 ms
42,704 KB
testcase_17 AC 111 ms
41,184 KB
testcase_18 AC 142 ms
43,420 KB
testcase_19 AC 134 ms
42,932 KB
testcase_20 AC 147 ms
43,644 KB
testcase_21 AC 166 ms
44,764 KB
権限があれば一括ダウンロードができます

ソースコード

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[] counts = new int[n];
        for (int i = 1; i < n; i++) {
            for (int j = 1; j * i < n; j++) {
                counts[j * i]++;
            }
        }
        int min = Integer.MAX_VALUE;
        ArrayList<Integer> ans = new ArrayList<>();
        for (int i = 1; i < n; i++) {
            int x = Math.abs(i - counts[i] - (n - i - counts[n - i]));
            if (min == x) {
                ans.add(i);
            } else if (min > x) {
                min = x;
                ans.clear();
                ans.add(i);
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int x : ans) {
            sb.append(x).append(" ").append(n - x).append("\n");
        }
        System.out.print(sb);
    }
}
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 String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0