結果

問題 No.2066 Simple Math !
ユーザー t98slidert98slider
提出日時 2022-09-04 20:46:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 676 bytes
コンパイル時間 744 ms
コンパイル使用メモリ 90,212 KB
最終ジャッジ日時 2024-04-29 20:29:59
合計ジャッジ時間 1,377 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:7:5: error: 'cin' was not declared in this scope
    7 |     cin >> t;
      |     ^~~
main.cpp:2:1: note: 'std::cin' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
    1 | #include<atcoder/all>
  +++ |+#include <iostream>
    2 | using namespace std;
main.cpp:14:13: error: 'cout' was not declared in this scope
   14 |             cout << g * k << '\n';
      |             ^~~~
main.cpp:14:13: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
main.cpp:27:9: error: 'cout' was not declared in this scope
   27 |         cout << g * ok << '\n';
      |         ^~~~
main.cpp:27:9: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?

ソースコード

diff #

#include<atcoder/all>
using namespace std;
using ll = long long;

int main(){
    int t;
    cin >> t;
    while(t--){
        ll p, q, k, g;
        cin >> p >> q >> k;
        g = __gcd(p, q);
        p /= g, q /= g;
        if(p == 1 || q == 1){
            cout << g * k << '\n';
            continue;
        }
        auto f = [&](ll v){
            ll r = min(q, v / p + 1);
            return atcoder::floor_sum(r, q, p, v + q - p * (r - 1));
        };
        ll ng = 0, ok = 1ll << 60, mid;
        while(ng + 1 < ok){
            mid = (ng + ok) / 2;
            if(f(mid) <= k)ng = mid;
            else ok = mid;
        }
        cout << g * ok << '\n';
    }
}
0