結果
| 問題 |
No.376 立方体のN等分 (2)
|
| コンテスト | |
| ユーザー |
tails
|
| 提出日時 | 2015-05-06 07:52:17 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 129 ms / 5,000 ms |
| コード長 | 875 bytes |
| コンパイル時間 | 1,781 ms |
| コンパイル使用メモリ | 166,544 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-23 22:28:12 |
| 合計ジャッジ時間 | 3,808 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
| 外部呼び出し有り |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 38 |
コンパイルメッセージ
main.cpp: In function ‘void factor(loong)’:
main.cpp:17:15: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
17 | fscanf(f,"%lld:",&x);
| ~~~~~~^~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long loong;
map<loong,int> e;
loong p[20];int pn;
loong ae[20];
loong n,m,a,t;
// 皆さんは自前のライブラリで素因数分解してください (^^)
void factor(loong n){
char cmd[256];
sprintf(cmd,"factor %lld",n);
FILE* f=popen(cmd,"r");
loong x;
fscanf(f,"%lld:",&x);
while(fscanf(f,"%lld",&x)==1){
if(++e[x]==1){
p[pn++]=x;
}
}
fclose(f);
}
void find_b(loong b,int i){
if(i==pn){
loong c=m/b;
if(t>a+b+c-3){
t=a+b+c-3;
}
}else{
for(int d=0;d<=e[p[i]]-ae[i]&&b*b<=m;++d,b*=p[i]){
find_b(b,i+1);
}
}
}
void find_a(loong a,int i){
if(i==pn){
::a=a;
m=n/a;
find_b(1,0);
}else{
for(int d=0;d<=e[p[i]]&&a*a*a<=n;++d,a*=p[i]){
ae[i]=d;
find_a(a,i+1);
}
}
}
int main(){
cin>>n;
factor(n);
t=n;
find_a(1,0);
cout<<t<<" "<<n-1<<endl;
return 0;
}
tails