結果
| 問題 |
No.1006 Share an Integer
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2022-10-06 08:46:56 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 186 ms / 2,000 ms |
| コード長 | 1,683 bytes |
| コンパイル時間 | 2,817 ms |
| コンパイル使用メモリ | 81,244 KB |
| 実行使用メモリ | 48,896 KB |
| 最終ジャッジ日時 | 2025-01-02 17:21:33 |
| 合計ジャッジ時間 | 6,178 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
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();
}
}
tenten