結果
| 問題 |
No.376 立方体のN等分 (2)
|
| コンテスト | |
| ユーザー |
IL_msta
|
| 提出日時 | 2017-02-16 21:57:32 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,140 bytes |
| コンパイル時間 | 1,747 ms |
| コンパイル使用メモリ | 122,192 KB |
| 実行使用メモリ | 9,888 KB |
| 最終ジャッジ日時 | 2024-12-30 01:07:10 |
| 合計ジャッジ時間 | 42,957 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 32 TLE * 6 |
ソースコード
#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;
}
IL_msta