結果
問題 | No.376 立方体のN等分 (2) |
ユーザー |
![]() |
提出日時 | 2016-06-04 23:48:32 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,052 bytes |
コンパイル時間 | 2,039 ms |
コンパイル使用メモリ | 180,648 KB |
実行使用メモリ | 10,020 KB |
最終ジャッジ日時 | 2024-10-08 10:36:40 |
合計ジャッジ時間 | 20,610 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 15 TLE * 1 -- * 22 |
ソースコード
#include <bits/stdc++.h> #include <random> using namespace std; #define rep(i,a,b) for(int i=a;i<b;i++) #define INF 1LL<<60 typedef long long ll; map<ll, int> enumdiv(ll n) { map<ll, int> V; if (n == 1) V[1] = 1; else { for (ll i = 2; i*i <= n; i++) while (n%i == 0) V[i]++, n /= i; if (n>1) V[n]++; } return V; } ll calc(vector<ll> primes) { random_device rnd; ll ans = INF; rep(i, 0, 1000000) { ll tmp[3] = { 1, 1, 1 }; rep(j, 0, primes.size()) { int r = rnd() % 3; tmp[r] *= primes[j]; } ll ret = 0; rep(j, 0, 3) ret += tmp[j] - 1; ans = min(ans, ret); } return ans; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll N; while (cin >> N) { auto ps = enumdiv(N); vector<ll> primes; for (auto p : ps) rep(i, 0, p.second) primes.push_back(p.first); //rep(i, 0, primes.size()) cout << primes[i] << " "; //cout << endl; ll ans = 0; if (3 < primes.size()) ans = calc(primes); else rep(i, 0, primes.size()) ans += primes[i] - 1LL; cout << ans << " " << (N - 1LL) << endl; } }