結果

問題 No.1006 Share an Integer
ユーザー Y17Y17
提出日時 2020-03-06 22:07:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 572 bytes
コンパイル時間 2,195 ms
コンパイル使用メモリ 162,140 KB
実行使用メモリ 18,944 KB
最終ジャッジ日時 2024-04-22 07:54:17
合計ジャッジ時間 4,694 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 60 ms
12,032 KB
testcase_12 AC 99 ms
18,040 KB
testcase_13 AC 94 ms
18,944 KB
testcase_14 AC 97 ms
18,944 KB
testcase_15 AC 84 ms
16,768 KB
testcase_16 AC 30 ms
10,240 KB
testcase_17 AC 45 ms
12,416 KB
testcase_18 AC 83 ms
17,024 KB
testcase_19 AC 71 ms
16,384 KB
testcase_20 AC 80 ms
17,408 KB
testcase_21 AC 97 ms
18,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long

int yaku[2000010];
int f(int x){
	return x - yaku[x];
}

signed main(){
	int x;
	cin >> x;

	for(int i = 1;i <= x;i++){
		for(int j = i;j <= x;j+=i){
			yaku[j]++;
		}
	}

	vector<pair<int, int>> ans;
	int anum = INT_MAX;
	for(int i = 1;i < x;i++){
		int a = i;
		int b = x-a;
		int score = abs(f(a)-f(b));
		if(score < anum){
			ans.clear();
			anum = score;
		}
		if(score == anum){
			ans.push_back({a, b});
		}
	}

	for(auto e : ans){
		cout << e.first << " " << e.second << endl;
	}

	return 0;
}
0