結果
問題 | No.376 立方体のN等分 (2) |
ユーザー |
![]() |
提出日時 | 2019-01-22 12:23:29 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 481 ms / 5,000 ms |
コード長 | 1,000 bytes |
コンパイル時間 | 900 ms |
コンパイル使用メモリ | 98,476 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-15 13:31:50 |
合計ジャッジ時間 | 5,125 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 38 |
ソースコード
#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <complex> #include <unordered_map> #include <unordered_set> #include <random> #include <cassert> using namespace std; typedef long long int ll; typedef pair<ll, int> P; ll n0; vector<P> f; ll a, b; ll tmin, tmax; void dfs(int i){ if(i==f.size()){ tmin=min(tmin, a+b+n0/a/b-3); tmax=max(tmax, a+b+n0/a/b-3); return; } int e=f[i].second; ll pa=1, p=f[i].first; for(int j=0; j<=e; j++){ ll pb=1; for(int k=0; k<=e-j; k++){ a*=pa, b*=pb; dfs(i+1); a/=pa, b/=pb; pb*=p; } pa*=p; } } int main() { ll n; cin>>n; n0=n; for(ll i=2; i*i<=n; i++){ if(n%i==0){ int e=0; while(n%i==0){ n/=i; e++; } f.push_back(P(i, e)); } } if(n>1) f.push_back(P(n, 1)); a=1, b=1, tmin=n0-1, tmax=0; dfs(0); cout<<tmin<<" "<<tmax<<endl; return 0; }