結果

問題 No.1006 Share an Integer
ユーザー Y17
提出日時 2020-03-06 22:07:02
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 572 bytes
コンパイル時間 1,835 ms
コンパイル使用メモリ 163,444 KB
実行使用メモリ 19,056 KB
最終ジャッジ日時 2024-10-14 07:08:52
合計ジャッジ時間 3,541 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

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