結果

問題 No.719 Coprime
ユーザー chocoruskchocorusk
提出日時 2019-01-22 11:44:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 100 ms / 3,000 ms
コード長 1,585 bytes
コンパイル時間 1,588 ms
コンパイル使用メモリ 98,768 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-13 17:38:15
合計ジャッジ時間 4,817 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 1 ms
4,356 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 1 ms
4,352 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,352 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 1 ms
4,352 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 2 ms
4,352 KB
testcase_28 AC 1 ms
4,352 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 1 ms
4,352 KB
testcase_31 AC 1 ms
4,352 KB
testcase_32 AC 1 ms
4,348 KB
testcase_33 AC 1 ms
4,348 KB
testcase_34 AC 2 ms
4,352 KB
testcase_35 AC 2 ms
4,352 KB
testcase_36 AC 2 ms
4,352 KB
testcase_37 AC 1 ms
4,348 KB
testcase_38 AC 1 ms
4,348 KB
testcase_39 AC 2 ms
4,356 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 1 ms
4,348 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 AC 1 ms
4,348 KB
testcase_44 AC 1 ms
4,352 KB
testcase_45 AC 1 ms
4,348 KB
testcase_46 AC 2 ms
4,348 KB
testcase_47 AC 2 ms
4,348 KB
testcase_48 AC 2 ms
4,348 KB
testcase_49 AC 1 ms
4,348 KB
testcase_50 AC 2 ms
4,352 KB
testcase_51 AC 2 ms
4,352 KB
testcase_52 AC 3 ms
4,348 KB
testcase_53 AC 6 ms
4,352 KB
testcase_54 AC 14 ms
4,352 KB
testcase_55 AC 30 ms
4,352 KB
testcase_56 AC 76 ms
4,348 KB
testcase_57 AC 77 ms
4,352 KB
testcase_58 AC 97 ms
4,352 KB
testcase_59 AC 100 ms
4,348 KB
testcase_60 AC 98 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, int> P;
const int MAX=1262;
bool isprime[MAX];
vector<int> prime;
void sieve(){
	for(int i=3; i<MAX; i+=2){
		isprime[i]=1;
	}
	isprime[2]=1;
	prime.push_back(2);
	for(int i=3; i<MAX; i++){
		if(isprime[i]){
			prime.push_back(i);
			for(int j=2*i; j<MAX; j+=i){
				isprime[j]=0;
			}
		}
	}
	return;
}
int main()
{
	sieve();
	int n; cin>>n;
	int b=(int)sqrt((double)n)+1;
	int t=lower_bound(prime.begin(), prime.end(), b)-prime.begin();
	int c=0; bool ok[1263]={};
	int dp[2][1<<11]={};
	for(int i=t; i<prime.size(); i++){
		if(prime[i]>n) break;
		for(int l=0; l<(1<<t); l++) dp[c^1][l]=dp[c][l];
		for(int l=0; l<(1<<t); l++){
			for(int j=1; j*prime[i]<=n; j++){
				ok[j*prime[i]]=1;
				int p=0;
				for(int k=0; k<t; k++){
					if(j%prime[k]==0) p^=(1<<k);
				}
				if(l&p) continue;
				dp[c^1][l^p]=max(dp[c][l]+j*prime[i], dp[c^1][l^p]);
			}
		}
		c^=1;
	}
	for(int i=2; i<=n; i++){
		if(ok[i]) continue;
		for(int l=0; l<(1<<t); l++) dp[c^1][l]=dp[c][l];
		for(int l=0; l<(1<<t); l++){
			int p=0;
			for(int k=0; k<t; k++){
				if(i%prime[k]==0) p^=(1<<k);
			}
			if(l&p) continue;
			dp[c^1][l^p]=max(dp[c][l]+i, dp[c^1][l^p]);
		}
		c^=1;
	}
	cout<<dp[c][(1<<t)-1]<<endl;
	return 0;
}
0