結果
| 問題 |
No.1899 L1 Cafe
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-01-31 06:19:29 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,181 bytes |
| コンパイル時間 | 751 ms |
| コンパイル使用メモリ | 66,848 KB |
| 最終ジャッジ日時 | 2025-01-27 18:02:01 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 7 TLE * 5 |
ソースコード
// 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/