結果

問題 No.1006 Share an Integer
ユーザー TAISA_TAISA_
提出日時 2020-03-06 22:03:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 921 bytes
コンパイル時間 1,573 ms
コンパイル使用メモリ 165,864 KB
実行使用メモリ 10,812 KB
最終ジャッジ日時 2023-08-04 10:07:25
合計ジャッジ時間 3,029 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 22 ms
7,388 KB
testcase_12 AC 30 ms
10,496 KB
testcase_13 AC 31 ms
10,664 KB
testcase_14 AC 31 ms
10,812 KB
testcase_15 AC 28 ms
9,696 KB
testcase_16 AC 19 ms
6,340 KB
testcase_17 AC 22 ms
7,436 KB
testcase_18 AC 28 ms
9,708 KB
testcase_19 AC 28 ms
9,476 KB
testcase_20 AC 29 ms
9,936 KB
testcase_21 AC 30 ms
10,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define all(v) v.begin(),v.end()
#define eb emplace_back
#define N 1000010
using namespace std;
using ll=long long;
using P=pair<int,int>;
const ll INF=1LL<<30;
inline void chmin(int &a,int b){a=min(a,b);}
int dy[4]={0,-1,0,1};
int dx[4]={1,0,-1,0};
int to[4]={2,3,0,1};
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int x;cin>>x;
	vector<int> d(x+10);
	for(int i=1;i<=x;i++){
		d[i]=i;
		
	}
	int mi=INF;
	for(int a=1;a<x;a++){
		int b=x-a;
		if(abs(a-b)>3000)continue;
		d[a]=a,d[b]=b;
		for(int j=1;j*j<=a;j++){
			if(a%j==0){
				if(j==a/j){
					d[a]--;
				}else{
					d[a]-=2;
				}
			}
		}
		for(int j=1;j*j<=b;j++){
			if(b%j==0){
				if(j==b/j){
					d[b]--;
				}else{
					d[b]-=2;
				}
			}
		}
		if(mi>abs(d[a]-d[b])){
			mi=abs(d[a]-d[b]);
		}
	}
	for(int a=1;a<x;a++){
		int b=x-a;
		if(abs(a-b)>3000)continue;
		if(mi==abs(d[a]-d[b])){
			cout<<a<<" "<<b<<endl;
		}
	}
}
0