結果

問題 No.376 立方体のN等分 (2)
ユーザー tailstails
提出日時 2015-05-06 00:32:28
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 863 bytes
コンパイル時間 1,366 ms
コンパイル使用メモリ 151,488 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-19 07:06:28
合計ジャッジ時間 5,352 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long loong;

map<loong,int> e;
loong p[20];int pn;
loong ae[20];
loong n,m,a,t;

// 皆さんは自前のライブラリで素因数分解してください (^^)
void factor(loong n){
	char cmd[256];
	sprintf(cmd,"factor %lld",n);
	FILE* f=popen(cmd,"r");
	loong x;
	fscanf(f,"%lld:",&x);
	while(fscanf(f,"%lld",&x)==1){
		if(++e[x]==1){
			p[pn++]=x;
		}
	}
	fclose(f);
}

void find_b(loong b,int i){
	if(i==pn){
		loong c=m/b;
		if(t>a+b+c-3){
			t=a+b+c-3;
		}
	}else{
		for(int d=0;d<=e[p[i]]-ae[i]&&b*b<=m;++d,b*=p[i]){
			find_b(b,i+1);
		}
	}
}

void find_a(loong a,int i){
	if(i==pn){
		::a=a;
		m=n/a;
		find_b(1,0);
	}else{
		for(int d=0;d<=e[p[i]]&&a*a*a<=n;++d,a*=p[i]){
			find_a(a,i+1);
		}
	}
}

int main(){
	cin>>n;
	factor(n);
	t=n;
	find_a(1,0);
	cout<<t<<" "<<n-1<<endl;
	return 0;
}
0