結果

問題 No.1006 Share an Integer
ユーザー Y17Y17
提出日時 2020-03-06 22:07:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 572 bytes
コンパイル時間 2,260 ms
コンパイル使用メモリ 148,004 KB
実行使用メモリ 19,108 KB
最終ジャッジ日時 2023-08-04 10:12:12
合計ジャッジ時間 4,469 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 58 ms
13,584 KB
testcase_12 AC 131 ms
18,180 KB
testcase_13 AC 138 ms
19,016 KB
testcase_14 AC 151 ms
19,108 KB
testcase_15 AC 107 ms
17,652 KB
testcase_16 AC 38 ms
11,512 KB
testcase_17 AC 59 ms
13,564 KB
testcase_18 AC 106 ms
17,656 KB
testcase_19 AC 99 ms
17,652 KB
testcase_20 AC 117 ms
17,864 KB
testcase_21 AC 139 ms
18,948 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