結果
| 問題 | No.915 Plus Or Multiple Operation |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-13 06:09:33 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 451 bytes |
| 記録 | |
| コンパイル時間 | 1,185 ms |
| コンパイル使用メモリ | 208,612 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-06-10 02:53:33 |
| 合計ジャッジ時間 | 2,154 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using lint=long long;
lint dfs(int a,int base){
lint res=(a+base-2)/(base-1);
if(a>0){
lint cnt=1;
if(a%base!=0) cnt++;
res=min(res,cnt+dfs(a/base,base));
}
return res;
}
int main(){
int q; scanf("%d",&q);
rep(_,q){
int a,b,base; scanf("%d%d%d",&a,&b,&base);
if(base==1) puts("-1");
else printf("%lld\n",b*dfs(a,base));
}
return 0;
}