結果

問題 No.376 立方体のN等分 (2)
ユーザー IL_mstaIL_msta
提出日時 2017-02-16 22:01:18
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 3,138 bytes
コンパイル時間 1,040 ms
コンパイル使用メモリ 117,440 KB
実行使用メモリ 7,608 KB
最終ジャッジ日時 2023-08-28 17:47:53
合計ジャッジ時間 10,716 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 10 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 5 ms
4,376 KB
testcase_16 AC 2,876 ms
4,376 KB
testcase_17 TLE -
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 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef __GNUC__
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#endif

#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>

#include <string>
#include <cstring>
#include <vector>
#include <valarray>
//#include <array>//x C++ (G++ 4.6.4)

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <cassert>//assert();
#include <fstream>
#include <random>
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)

/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#define PII pair<int,int>
/////////
using namespace::std;

// 最大公約数
template<class T>
inline T gcd(T a, T b){return b == 0 ? a : gcd(b, a % b);}
// 最小公倍数
template<class T>
inline T lcm(T a, T b){return a * b / gcd(a, b);}
////////////////////////////////
vector<LL> SerNum;
vector<LL> SerVal(3,0);
int MaxDepth;
LL MinDfs = (LL)100000000000000;
//pos,
void dfs(int pos, vector<LL>& vv){
	if( pos >= MaxDepth ){
		if( vv[0] == 1 || vv[1] == 1 || vv[2] == 1 ) return;
		LL temp = vv[0]+vv[1]+vv[2];
		if( temp < MinDfs ){
			MinDfs = temp;
			SerVal = vv;
		}
		return;
	}

	if( MinDfs < vv[0]+vv[1]+vv[2] ) return;

	for(int i=0;i<3;++i){
		vv[i] *= SerNum[pos];
		dfs(pos+1,vv);
		vv[i] /= SerNum[pos];
	}
}
inline void solve(){
	LL N;
	cin >> N;
	int CountAll = 0;
	int Count = 0;
	vector<LL> prime;
	vector<int> P;
	LL T = N;
	if( T % 2 == 0 ){
		prime.push_back(2);
		P.push_back(0);
		while(T%2 == 0 ){
			T /= 2;
			P[Count]++;
			++CountAll;
		}
		++Count;
	}
	for(LL i=3;i*i<=T;i+=2){
		if( T % i == 0 ){
			prime.push_back(i);
			P.push_back(0);
			while( T% i == 0 ){
				T /= i;
				P[Count]++;
				++CountAll;
			}
			++Count;
		}
	}
	if( T != 1 ){
		prime.push_back(T);
		P.push_back(1);
		++Count;
		++CountAll;
	}
	T = 0;
	//
	if( CountAll == 1 ){
		cout << N-1 << ' ' << N-1 << endl;
		return;
	}
	if( CountAll == 2){
		vector<LL> ans(3);
		for(int i=0;i<Count;++i){
			if(P[i]){
				ans[0] = prime[i]-1;
				P[i]--;
				break;
			}
		}
		for(int i=0;i<Count;++i){
			if( P[i] ){
				ans[1] = prime[i]-1;
				P[i]--;
				break;
			}
		}
		cout << ans[0]+ans[1] << ' ' << N-1;
		return;
	}
	vector<LL> ans(3,1);
	int SerCount = 0;
	
	for(int i=0;i<Count;++i){
		/*while(P[i] >= 3 ){//!?
			ans[0] *= prime[i];
			ans[1] *= prime[i];
			ans[2] *= prime[i];
			P[i] -= 3;
		}*/
		if( P[i] ){
			SerCount++;
			while(P[i] ){
				SerNum.push_back(prime[i]);
				P[i]--;
			}
		}
	}
	
	MaxDepth = SerNum.size();
	if( MaxDepth == 0 ){
		LL temp = 0;
		for(int i=0;i<3;++i){
			temp += ans[i]-1;
		}
		cout << temp << ' ' << N-1 << endl;
		return;
	}
	vector<LL> val(3,1);
	ans[0] *= SerNum[0];
	dfs(1,ans);
	LL temp = 0;
	for(int i=0;i<3;++i){
		temp += SerVal[i]-1;
	}
	cout << temp << ' ' << N-1 << endl;
	
	
}

int main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	//std::cout << std::fixed;//小数を10進数表示
	//cout << setprecision(16);//小数をいっぱい表示する。16?
	
	solve();
	return 0;
}
0