結果

問題 No.1006 Share an Integer
ユーザー furafura
提出日時 2020-03-06 21:37:57
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 247 ms / 2,000 ms
コード長 1,247 bytes
コンパイル時間 2,214 ms
コンパイル使用メモリ 200,720 KB
実行使用メモリ 19,668 KB
最終ジャッジ日時 2024-04-22 05:24:27
合計ジャッジ時間 5,515 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
11,984 KB
testcase_01 AC 20 ms
12,108 KB
testcase_02 AC 20 ms
12,116 KB
testcase_03 AC 19 ms
11,984 KB
testcase_04 AC 19 ms
11,988 KB
testcase_05 AC 20 ms
11,868 KB
testcase_06 AC 19 ms
12,112 KB
testcase_07 AC 19 ms
11,980 KB
testcase_08 AC 18 ms
11,980 KB
testcase_09 AC 19 ms
11,988 KB
testcase_10 AC 20 ms
11,984 KB
testcase_11 AC 135 ms
16,336 KB
testcase_12 AC 227 ms
19,284 KB
testcase_13 AC 243 ms
19,668 KB
testcase_14 AC 245 ms
19,664 KB
testcase_15 AC 211 ms
18,512 KB
testcase_16 AC 112 ms
15,184 KB
testcase_17 AC 139 ms
16,468 KB
testcase_18 AC 209 ms
18,640 KB
testcase_19 AC 205 ms
18,256 KB
testcase_20 AC 213 ms
18,768 KB
testcase_21 AC 247 ms
19,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

class linear_sieve{
	vector<int> lpf,p;
public:
	linear_sieve(int n):lpf(n+1){
		for(int i=2;i<=n;i++){
			if(lpf[i]==0){
				lpf[i]=i;
				p.emplace_back(i);
			}
			for(int j=0;j<p.size()&&p[j]<=lpf[i]&&i*p[j]<=n;j++) lpf[i*p[j]]=p[j];
		}
	}

	const vector<int>& primes()const{ return p; }

	bool is_prime(int a)const{
		assert(a<=(int)lpf.size()-1);
		return a>0 && lpf[a]==a;
	}

	map<int,int> prime_factorize(int a)const{
		assert(a<=(int)lpf.size()-1);
		map<int,int> pf;
		for(;a>1;a/=lpf[a]) ++pf[lpf[a]];
		return pf;
	}

	int number_of_divisors(int a)const{
		assert(a<=(int)lpf.size()-1);
		int res=1,cnt=0,pre=-1;
		for(;a>1;a/=lpf[a]){
			if(pre==-1 || lpf[a]==pre){
				cnt++;
			}
			else{
				res*=cnt+1;
				cnt=1;
			}
			pre=lpf[a];
		}
		res*=cnt+1;
		return res;
	}
};

const int INF=1<<29;

int main(){
	linear_sieve S(2e6);

	int n; scanf("%d",&n);
	vector<int> res(n);
	res[0]=INF;
	for(int a=1;a<n;a++){
		int fa=a-S.number_of_divisors(a);
		int fb=n-a-S.number_of_divisors(n-a);
		res[a]=abs(fa-fb);
	}

	int mn=*min_element(res.begin(),res.end());
	for(int a=1;a<n;a++){
		if(res[a]==mn) printf("%d %d\n",a,n-a);
	}

	return 0;
}
0