結果

問題 No.1006 Share an Integer
ユーザー forest3forest3
提出日時 2020-07-15 14:15:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 680 bytes
コンパイル時間 1,900 ms
コンパイル使用メモリ 177,012 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 14:56:17
合計ジャッジ時間 2,787 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 13 ms
6,940 KB
testcase_12 AC 15 ms
6,944 KB
testcase_13 AC 16 ms
6,940 KB
testcase_14 AC 16 ms
6,940 KB
testcase_15 AC 15 ms
6,940 KB
testcase_16 AC 12 ms
6,944 KB
testcase_17 AC 13 ms
6,940 KB
testcase_18 AC 15 ms
6,940 KB
testcase_19 AC 14 ms
6,940 KB
testcase_20 AC 15 ms
6,940 KB
testcase_21 AC 16 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int f( int N )
{
	int d = 0;
	for( int n = 1; n * n <= N; n++ ) {
		if( N % n == 0 ) {
			d++;
			if( n != N / n ) d++;
		}
	}
	return N - d;
};

int main()
{
	int X;
	cin >> X;

	int half = X / 2;
	int start = max( 1, half - 1000 );
	int end = min( X, half + 1001 );
	vector<tuple<int, int, int>> tp;
	for( int A = start; A < end; A++ ) {
		int B = X - A;
		int a = f( A );
		int b = f( B );
		tp.push_back( make_tuple( abs( a - b ), A, B ) );
	}
	sort( tp.begin(), tp.end() );

	for( int i = 0, mi = get<0>( tp[0] ); i < tp.size() && get<0>( tp[i] ) == mi; i++ ) {
		cout << get<1>( tp[i] ) << " " << get<2>( tp[i] ) << endl;
	}
}
0