結果

問題 No.3413 あわてんぼうのルクくん
コンテスト
ユーザー GOTKAKO
提出日時 2025-12-20 02:08:35
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
結果
WA  
実行時間 -
コード長 809 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,848 ms
コンパイル使用メモリ 195,340 KB
実行使用メモリ 7,852 KB
最終ジャッジ日時 2025-12-20 02:08:41
合計ジャッジ時間 4,950 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int Q; cin >> Q;
    while(Q--){
        long long X,N,D; cin >> X >> N >> D;
        if(gcd(X,D) > 1){cout << "inf\n"; continue;}
        if(X == 1){cout << "-1\n"; continue;}
        if(D == 1){
            long long need = (X+N-1)/N;
            cout << X*need-1 << "\n";
            continue;
        }
        long long low = 0,high = 2e9;
        while(high-low > 1){
            long long mid = (high+low)/2;
            __int128_t x = X*mid+(__int128_t)D*N*mid;
            __int128_t y = X*(mid+D-1);
            if(x > y) high = mid;
            else low = mid;
        }
        {
            long long y = X*(high+D-1);
            cout << y-D << "\n";
        }
    }   
}
0