結果

問題 No.1006 Share an Integer
ユーザー 37zigen37zigen
提出日時 2020-03-06 22:31:36
言語 Java21
(openjdk 21)
結果
AC  
実行時間 362 ms / 2,000 ms
コード長 822 bytes
コンパイル時間 2,646 ms
コンパイル使用メモリ 86,328 KB
実行使用メモリ 68,320 KB
最終ジャッジ日時 2024-04-22 08:57:56
合計ジャッジ時間 10,880 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 342 ms
67,968 KB
testcase_01 AC 305 ms
67,732 KB
testcase_02 AC 302 ms
67,772 KB
testcase_03 AC 326 ms
67,864 KB
testcase_04 AC 301 ms
68,048 KB
testcase_05 AC 301 ms
67,844 KB
testcase_06 AC 335 ms
67,856 KB
testcase_07 AC 305 ms
67,668 KB
testcase_08 AC 303 ms
67,960 KB
testcase_09 AC 309 ms
67,792 KB
testcase_10 AC 303 ms
67,740 KB
testcase_11 AC 329 ms
68,320 KB
testcase_12 AC 360 ms
68,120 KB
testcase_13 AC 339 ms
68,236 KB
testcase_14 AC 362 ms
68,156 KB
testcase_15 AC 330 ms
68,100 KB
testcase_16 AC 327 ms
67,948 KB
testcase_17 AC 328 ms
68,188 KB
testcase_18 AC 357 ms
68,264 KB
testcase_19 AC 334 ms
67,972 KB
testcase_20 AC 341 ms
68,232 KB
testcase_21 AC 338 ms
68,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
	
	int NMAX=(int)3e6;
	int[] d=new int[NMAX];
	{
		for(int div=1;div<NMAX;++div){
			for(int i=1;i*div<NMAX;++i){
				d[i*div]++;
			}
		}
	}
	
	int f(int n){
		return n-d[n];
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int X=sc.nextInt();
		int min=Integer.MAX_VALUE;
		for(int A=1;A<=X-1;++A){
			int B=X-A;
			min=Math.min(min,Math.abs(f(A)-f(B)));
		}
		for(int A=1;A<=X-1;++A){
			int B=X-A;
			int v=Math.abs(f(A)-f(B));
			if(v==min){
				System.out.println(A+" "+B);
			}
		}
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
	
}
0