結果

問題 No.1006 Share an Integer
ユーザー furafura
提出日時 2020-03-06 21:25:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,286 bytes
コンパイル時間 2,660 ms
コンパイル使用メモリ 209,252 KB
実行使用メモリ 15,672 KB
最終ジャッジ日時 2024-04-22 04:53:13
合計ジャッジ時間 6,320 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
7,820 KB
testcase_01 AC 10 ms
7,820 KB
testcase_02 AC 10 ms
7,584 KB
testcase_03 AC 10 ms
7,820 KB
testcase_04 AC 10 ms
7,568 KB
testcase_05 AC 11 ms
7,692 KB
testcase_06 AC 10 ms
7,692 KB
testcase_07 AC 11 ms
7,704 KB
testcase_08 AC 10 ms
7,692 KB
testcase_09 AC 10 ms
7,564 KB
testcase_10 AC 11 ms
7,692 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 797 ms
10,984 KB
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
権限があれば一括ダウンロードができます

ソースコード

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;
	}
};

template<class T>
vector<T> divisors(const map<T,int>& pf){
	vector<T> res={T(1)};
	for(const auto& q:pf){
		int m=res.size();
		T pp=1;
		rep(i,q.second){
			pp*=q.first;
			rep(i,m) res.emplace_back(res[i]*pp);
		}
	}
	sort(res.begin(),res.end());
	return res;
}

const int INF=1<<29;

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

	int n; scanf("%d",&n);
	vector<int> res(n);
	res[0]=INF;
	for(int a=1;a<n;a++){
		int fa=a-divisors(S.prime_factorize(a)).size();
		int fb=(n-a)-divisors(S.prime_factorize(n-a)).size();
		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