結果

問題 No.915 Plus Or Multiple Operation
ユーザー erbowlerbowl
提出日時 2020-05-07 00:11:22
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 686 bytes
コンパイル時間 3,008 ms
コンパイル使用メモリ 191,600 KB
最終ジャッジ日時 2025-01-10 07:21:32
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;

int main() {
    ll q;
    std::cin >> q;
    
    for (int i = 0; i < q; i++) {
        ll a,b,c;
        std::cin >> a>>b>>c;
        if(c==1){
            std::cout << -1 << std::endl;
            continue;
        }
        
        ll cnt = 0;
        while(a%c>0||a/c>0){
            if(c*c>a&&a%c!=0&&a%c<=c-2&&a/c%c==1){
                cnt+=2;
                a-=a%c+c;
            }else if(a%c==0){
                cnt++;
                a/=c;
            }else{
                a-=a%c;
                cnt++;
            }
        }
        std::cout << cnt*b << std::endl;
    }
}
0