結果

問題 No.719 Coprime
ユーザー ryoissyryoissy
提出日時 2018-07-28 13:36:53
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,022 bytes
コンパイル時間 1,970 ms
コンパイル使用メモリ 147,400 KB
実行使用メモリ 5,892 KB
最終ジャッジ日時 2023-09-19 06:08:58
合計ジャッジ時間 9,083 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,388 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,384 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 3 ms
4,380 KB
testcase_46 AC 3 ms
4,380 KB
testcase_47 AC 4 ms
4,380 KB
testcase_48 AC 4 ms
4,376 KB
testcase_49 AC 4 ms
4,376 KB
testcase_50 AC 4 ms
4,380 KB
testcase_51 AC 4 ms
4,376 KB
testcase_52 AC 11 ms
4,376 KB
testcase_53 AC 34 ms
4,376 KB
testcase_54 AC 107 ms
4,376 KB
testcase_55 AC 243 ms
4,804 KB
testcase_56 AC 617 ms
5,620 KB
testcase_57 AC 619 ms
5,812 KB
testcase_58 RE -
testcase_59 RE -
testcase_60 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
vector<int> vec;
vector<int> vec2;
bool prime[1263];
int dp[200][1<<12];

void dfs(int cur,int bit,int nbit,int val,int sum){
	//printf("%d %d %d %d %d\n",cur,bit,nbit,val,sum);
	if(val!=1)dp[cur+1][bit|nbit]=max(dp[cur+1][bit|nbit],sum+val);
	for(int i=0;i<vec2.size();i++){
		if(!(bit>>i & 1) && val*vec2[i]<=n){
			dfs(cur,bit,nbit|(1<<i),val*vec2[i],sum);
		}
	}
}

int main(void){
	scanf("%d",&n);
	memset(prime,true,sizeof(prime));
	prime[0]=false;
	prime[1]=false;
	for(int i=0;i<20;i++){
		vec.push_back(1);
	}
	for(int i=2;i<=n;i++){
		if(prime[i]){
			if(i*i<=n)vec2.push_back(i);
			else vec.push_back(i);
			for(int j=i*2;j<=n;j+=i){
				prime[j]=false;
			}
		}
	}
	for(int i=0;i<vec.size();i++){
		for(int j=0;j<(1<<(int)vec2.size());j++){
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
			dfs(i,j,0,vec[i],dp[i][j]);
		}
	}
	printf("%d\n",dp[vec.size()][(1<<vec2.size())-1]);
	return 0;
}
0