結果

問題 No.1006 Share an Integer
ユーザー furafura
提出日時 2020-03-07 00:13:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 233 ms / 2,000 ms
コード長 1,180 bytes
コンパイル時間 1,990 ms
コンパイル使用メモリ 200,712 KB
実行使用メモリ 19,820 KB
最終ジャッジ日時 2024-04-22 11:02:47
合計ジャッジ時間 4,919 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
11,988 KB
testcase_01 AC 16 ms
12,108 KB
testcase_02 AC 15 ms
12,116 KB
testcase_03 AC 14 ms
12,112 KB
testcase_04 AC 15 ms
11,988 KB
testcase_05 AC 15 ms
11,984 KB
testcase_06 AC 14 ms
12,108 KB
testcase_07 AC 14 ms
11,984 KB
testcase_08 AC 15 ms
11,984 KB
testcase_09 AC 15 ms
11,988 KB
testcase_10 AC 15 ms
12,108 KB
testcase_11 AC 123 ms
16,304 KB
testcase_12 AC 219 ms
19,288 KB
testcase_13 AC 233 ms
19,820 KB
testcase_14 AC 230 ms
19,768 KB
testcase_15 AC 193 ms
18,488 KB
testcase_16 AC 100 ms
15,188 KB
testcase_17 AC 133 ms
16,320 KB
testcase_18 AC 196 ms
18,668 KB
testcase_19 AC 193 ms
18,288 KB
testcase_20 AC 202 ms
18,752 KB
testcase_21 AC 233 ms
19,756 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 || pre==lpf[a]){
				cnt++;
			}
			else{
				res*=cnt+1;
				cnt=1;
			}
			pre=lpf[a];
		}
		return res*(cnt+1);
	}
};

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

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

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

	return 0;
}
0