結果

問題 No.375 立方体のN等分 (1)
ユーザー kongarishisyamokongarishisyamo
提出日時 2016-06-06 23:47:42
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 968 bytes
コンパイル時間 477 ms
コンパイル使用メモリ 59,900 KB
実行使用メモリ 13,880 KB
最終ジャッジ日時 2024-04-17 05:24:49
合計ジャッジ時間 7,177 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 4 ms
5,376 KB
testcase_02 AC 4 ms
5,376 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 4 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 5 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cmath>

using namespace std;

#define MAX 316228

long long N;
bool arr[MAX+1];
long long insuu[MAX];
long long insuun=0;
long long pn[MAX];
long long pc=0;

long long min(long long a,long long b){
	return (a<b)?a:b;
}

long long search(long long a,long long b,long long c,int sn){
	if(sn==insuun) return a+b+c;
	return min(search(a*insuu[sn],b,c,sn+1),min(search(a,b*insuu[sn],c,sn+1),search(a,b,c*insuu[sn],sn+1)));
}

int main(){

	cin>>N;

	long long ansmax=N-1;

	for(long long i=0;i<=MAX;i++){
		arr[i]=true;
	}

	arr[0]=false;
	arr[1]=false;

	for(long long i=2;i<=MAX;i++){
		if(arr[i]){
			pn[pc]=i;
			pc++;
			for(long long j=i*2;j<=MAX;j+=i){
				arr[j]=false;
			}
		}
	}

	for(long long i=0;i<pc;i++) insuu[i]=0;

	for(long long i=0;i<pc;i++){
		while(N%pn[i]==0){
			N/=pn[i];
			insuu[insuun]=pn[i];
			insuun++;
		}
		if(N==1) break;
	}

	if(N!=1) insuu[insuun]=N,insuun++;

	cout<<search(1,1,1,0)-3<<" "<<ansmax<<endl;
}

0