結果

問題 No.1006 Share an Integer
ユーザー SSRSSSRS
提出日時 2020-11-07 11:45:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 637 bytes
コンパイル時間 626 ms
コンパイル使用メモリ 73,404 KB
実行使用メモリ 18,720 KB
最終ジャッジ日時 2023-09-29 20:31:24
合計ジャッジ時間 2,583 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 39 ms
11,992 KB
testcase_12 AC 83 ms
17,772 KB
testcase_13 AC 89 ms
18,720 KB
testcase_14 AC 88 ms
18,660 KB
testcase_15 AC 72 ms
16,444 KB
testcase_16 AC 28 ms
9,556 KB
testcase_17 AC 38 ms
11,916 KB
testcase_18 AC 70 ms
16,432 KB
testcase_19 AC 62 ms
15,972 KB
testcase_20 AC 73 ms
17,068 KB
testcase_21 AC 88 ms
18,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <utility>
using namespace std;
const int INF = 10000000;
int main(){
	int X;
	cin >> X;
	vector<int> d(X, 0);
	for (int i = 1; i < X; i++){
		for (int j = i; j < X; j += i){
			d[j]++;
		}
	}
	vector<int> f(X);
	for (int i = 1; i < X; i++){
		f[i] = i - d[i];
	}
	vector<pair<int, int>> ans;
	int mn = INF;
	for (int i = 1; i < X; i++){
		int d = abs(f[i] - f[X - i]);
		if (mn > d){
			ans.clear();
			mn = d;
		}
		if (mn == d){
			ans.push_back(make_pair(i, X - i));
		}
	}
	int sz = ans.size();
	for (int i = 0; i < sz; i++){
		cout << ans[i].first << ' ' << ans[i].second << endl;
	}
}
0