結果
問題 | No.376 立方体のN等分 (2) |
ユーザー |
|
提出日時 | 2016-06-04 23:05:03 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 110 ms / 5,000 ms |
コード長 | 1,924 bytes |
コンパイル時間 | 1,954 ms |
コンパイル使用メモリ | 181,732 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-06 21:44:25 |
合計ジャッジ時間 | 4,218 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 38 |
ソースコード
#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)<<endl #define smax(x,y) (x)=max((x),(y)) #define smin(x,y) (x)=min((x),(y)) #define MEM(x,y) memset((x),(y),sizeof (x)) #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vll; map<ll, int> factorize(ll n){ map<ll, int> res; for(ll i=2; i*i<=n; ++i){ while(n%i==0){ n /= i; ++res[i]; } } if(n!=1) ++res[n]; return res; } class Divisors{ public: Divisors(ll n){ if(n == 0)return; factors=factorize(n); auto it=factors.begin(); rec(it, 1ll, result); } vector<ll> get(){ return result; } private: map<ll, int> factors; vector<ll> result; void rec(map<ll, int>::iterator it, ll value, vector<ll> &res){ if(it == factors.end()){ res.push_back(value); return; } auto nextIt = next(it); ll po = 1; rep(i, it->second+1){ rec(nextIt, value*po, res); po *= it->first; } } }; ll N; int main(){ while(cin >> N){ ll mini = LLONG_MAX, maxi = 0; auto divs = Divisors(N).get(); sort(all(divs)); int D = sz(divs); rep(i, D){ ll w = divs[i]; if(w*w*w > N)break; FOR(j, i, D){ ll h = divs[j]; if(w*h*h > N)break; ll d = N / (w*h); if(w*h*d == N){ smin(mini, d + w + h - 3); smax(maxi, d + w + h - 3); } } } cout << mini << " " << maxi << endl; } }