結果
| 問題 | No.2066 Simple Math ! |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-09-26 03:13:15 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
WA
不安定
|
| 実行時間 | - |
| コード長 | 2,261 bytes |
| 記録 | |
| コンパイル時間 | 3,521 ms |
| コンパイル使用メモリ | 337,664 KB |
| 実行使用メモリ | 9,928 KB |
| 最終ジャッジ日時 | 2026-09-26 03:14:19 |
| 合計ジャッジ時間 | 10,229 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 23 WA * 8 |
ソースコード
/*
#include<kyopro/master>
namespace my{entry
void main(){
multi_test_cases
LL(a,b,K);K++;
ll g=gcd(a,b);
a/=g,b/=g;
ll N=binary_search_first_true(1,oo,[&](ll N){
ll L=min(b,N/a+1);
return floor_sum(L,b,-a,N)+L>=K;
});
pp(N*g);
}}*/
#include<bits/stdc++.h>
#if __has_include(<atcoder/all>)
#endif
using namespace std;
#define RD(T,...) T __VA_ARGS__;lin(__VA_ARGS__)
#define LL(...) RD(ll,__VA_ARGS__)
#define FO(n) for(ll IJK=n;IJK-->0;)
#define defpp template<ostream&o=cout>void pp(const auto&...a){[[maybe_unused]]const char*c="";((o<<c<<a,c=" "),...);o<<'\n';}void epp(const auto&...a){pp<cerr>(a...);}
#define entry defpp void main();void main2();}int main(){my::io();my::main();}namespace my{
#define multi_test_cases LL(T);FO(T)main2();}void main2(){
namespace my{
void io(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);}
using ll=long long;
using lll=__int128_t;
void lin(auto&...a){(cin>>...>>a);}
constexpr auto abs(auto x){return x<0?-x:x;}
constexpr ll size10(auto x){x|=1;ll r=0;while(x>0)x/=10,++r;return r;}
template<class T>constexpr ll maxsize10(){return size10(numeric_limits<T>::max());}
auto min(auto...a){return min(initializer_list<common_type_t<decltype(a)...>>{a...});}
template<class T,class U>common_type_t<T,U>gcd(T a,U b){return b?gcd(b,a%b):abs(a);}
ll binary_search_first_true(ll l,ll r,auto&&f){while(l+1<r)(f((l+r)/2)?r:l)=(l+r)/2;return r;}
template<bool is_negative=false>struct infinity{
template<integral T>static constexpr T ones(size_t n){return n?ones<T>(n-1)*10+1:0;}
template<integral T>constexpr operator T()const{return ones<T>(maxsize10<T>())*(1-is_negative*2);}
};
constexpr infinity oo;
}
namespace my{
template<class T=lll>T floor_sum(lll n,lll m,lll a,lll b){
if(n<=0)return 0;
if(a<0)return-floor_sum<T>(n,m,-a,-b+m-1);
if(b<0)return floor_sum<T>(n,m,a,b*(1-m))+(T)b*n;
if(a>=m||b>=m)return floor_sum<T>(n,m,a%m,b%m)+(T)(n-1)*n/2*(a/m)+(T)n*(b/m);
if(a==0)return 0;
return floor_sum<T>((a*n+b)/m,a,m,(a*n+b)%m);
}
}
namespace my{entry
void main(){
multi_test_cases
LL(a,b,K);K++;
ll g=gcd(a,b);
a/=g,b/=g;
ll N=binary_search_first_true(1,oo,[&](ll N){
ll L=min(b,N/a+1);
return floor_sum(L,b,-a,N)+L>=K;
});
pp(N*g);
}}