結果

問題 No.1899 L1 Cafe
ユーザー 37zigen37zigen
提出日時 2022-01-31 06:19:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,181 bytes
コンパイル時間 966 ms
コンパイル使用メモリ 67,968 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-05-06 02:03:54
合計ジャッジ時間 4,801 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
using namespace std;

long long gcd(long a, long b) {
    if (b==0) return a;
    return gcd(b, a%b);
}

int main()
{
    int T;
    cin >> T;
    while (T-->0) {
        int N, A, B;
        cin >> N >> A >> B;
        long long ans=0;
        {
            int top=N-A;
            int bottom=A-(A-N%A)%A;
            ans+=(long long)((top-bottom)/A+1)*(top+bottom)/2;
        }
        {
            int top=N-B;
            int bottom=B-(B-N%B)%B;
            ans+=(long long)((top-bottom)/B+1)*(top+bottom)/2;
        }
        int i=1;
        long long g=gcd(A, B);
        N/=g;
        A/=g;
        B/=g;
        if (A<B) swap(A, B);
        while (i<=N/A) {
            int k=(N-A*i)/B;
            int ni=(N-B*k)/A+1;
            ans-=(long long)k*(ni-i);
            i=ni;
        }
        cout << ans << endl;
    }
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/
0