結果

問題 No.1006 Share an Integer
ユーザー tentententen
提出日時 2020-08-21 18:16:30
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,950 bytes
コンパイル時間 2,403 ms
コンパイル使用メモリ 79,744 KB
実行使用メモリ 65,904 KB
最終ジャッジ日時 2024-04-23 05:13:05
合計ジャッジ時間 7,679 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
61,144 KB
testcase_01 AC 135 ms
54,108 KB
testcase_02 AC 136 ms
54,140 KB
testcase_03 AC 137 ms
54,212 KB
testcase_04 AC 135 ms
54,436 KB
testcase_05 AC 138 ms
54,120 KB
testcase_06 AC 141 ms
54,268 KB
testcase_07 AC 139 ms
54,228 KB
testcase_08 AC 139 ms
54,076 KB
testcase_09 AC 139 ms
54,228 KB
testcase_10 AC 140 ms
54,100 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int[] counts = new int[x + 1];
		for (int i = 1; i <= x; i++) {
		    counts[i] = i - getCount(i);
		}
		int min = Integer.MAX_VALUE;
		Answer.size = x;
		ArrayList<Answer> list = new ArrayList<>();
		for (int i = 1; i <= x / 2; i++) {
		    if (min >= Math.abs(counts[i] - counts[x - i])) {
		        if (min > Math.abs(counts[i] - counts[x - i])) {
		            list.clear();
		            min = Math.abs(counts[i] - counts[x - i]);
		        }
		        list.add(new Answer(i));
		        if (i * 2 < x) {
		            list.add(new Answer(x - i));
		        }
		    }
		}
		Collections.sort(list);
		StringBuilder sb = new StringBuilder();
		for (Answer a : list) {
		    sb.append(a).append("\n");
		}
		System.out.print(sb);
    }
    
    static int getCount(int x) {
        if (x == 1) {
            return 1;
        } else {
            int count = 2;
            for (int i = 2; i <= Math.sqrt(x); i++) {
                if (x % i != 0) {
                    continue;
                }
                if (i * i == x) {
                    count++;
                } else {
                    count += 2;
                }
            }
            return count;
        }
    }
    
    static class Answer implements Comparable<Answer> {
        static int size;
        int left;
        int right;
        
        public Answer(int left, int right) {
            this.left = left;
            this.right = right;
        }
        
        
        public Answer(int left) {
            this(left, size - left);
        }
        
        public int compareTo(Answer another) {
            return left - another.left;
        }
        
        public String toString() {
            return new StringBuilder().append(left).append(" ").append(right).toString();
        }
    }
}

0