結果

問題 No.2128 Round up!!
ユーザー logxlogx
提出日時 2022-11-18 23:17:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,206 bytes
コンパイル時間 3,103 ms
コンパイル使用メモリ 205,284 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 08:18:15
合計ジャッジ時間 4,638 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#ifdef LOGX
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/modint>
using namespace atcoder;

/*---------macro---------*/
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define unless(x) if(!(x))
#define until(x) while(!(x))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define mybit(i,j) (((i)>>(j))&1)

/*---------type/const---------*/
//constexpr int big=1000000007;
constexpr int big=998244353;
constexpr double EPS=1e-8; //適宜変える
typedef long long ll;
typedef unsigned long long ull;
typedef std::string::const_iterator state; //構文解析
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
constexpr char newl='\n';
struct{
    constexpr operator int(){return -int(1e9)-10;}
    constexpr operator ll(){return -ll(1e18)-10;}
}neginf;
struct{
    constexpr operator int(){return int(1e9)+10;}
    constexpr operator ll(){return ll(1e18)+10;}
    constexpr auto operator -(){return neginf;}
}inf;

/*---------debug---------*/
#ifdef LOGX
#include <template/debug.hpp>
#else
#define dbg(...) ;
#define dbgnewl ;
#define prt(x) ;
#define _prt(x) ;
#endif

/*---------function---------*/
template<typename T> T max(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=max(ans,elem);}return ans;}
template<typename T> T min(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=min(ans,elem);}return ans;}
template<typename T,typename U> bool chmin(T &a,const U b){if(a>b){a=b;return true;}return false;}
template<typename T,typename U> bool chmax(T &a,const U b){if(a<b){a=b;return true;}return false;}
bool valid(int i,int j,int h,int w){return (i>=0 && j>=0 && i<h && j<w);}
template<class T,class U>T expm(T x,U y,const ll mod=big){T res=1;while(y){if(y&1)(res*=x)%=mod;(x*=x)%=mod;y>>=1;}return res;}
template<class T,class U>T exp(T x,U y){T res=1;while(y){if(y&1)res*=x;x*=x;y>>=1;}return res;}

using mint=modint998244353;
const mint inv2=499122177, inv6=166374059;

//~(i-1)^2
mint sum_2(ll i){
    return mint(i-1)*i*mint(2*i-1)*inv6;
}
//i^2~(j-1)^2
mint sum_2(ll i,ll j){
    return sum_2(j)-sum_2(i);
}
//~i-1
mint sum_1(ll i){
    return mint(i-1)*i*inv2;
}
mint sum_1(ll i,ll j){
    return sum_1(j)-sum_1(i);
}

ll mylcm(ll a,ll b){
    ll g=gcd(a,b);
    a/=g;
    //if(a*b>inf)
    if(a>ll(inf)/b)return inf;
    return a*b;
}

ll solve(){
    ll x,a,b;
    cin >> x >> a >> b;
    if(a==b){
        return (x%a==0 ? 1:2);
    }
    if(a>b)swap(a,b);
    x%=mylcm(a,b);
    if(b%a==0){
        if(x%a!=0 && (x+a-1)/a * a != (x+b-1)/b * b)return 3;
        if(x%a!=0)return 2;
        if(x%b==0)return 1;
        return 2;
    }
    ll g=gcd(a,b);
    //xより大きなBの倍数の個数
    ll B=a/g-(x/b);
    //Aの倍数の方が細かくあるので、減る
    ll ma=(x+a-1)/a * a;
    if(ma==x)ma+=a;
    ll A=B-1;
    if(ma < (x+b-1)/b * b && x%a!=0)A++;
    return (A+B+1)%big;
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(10);
/*------------------------------------*/

    int t;
    cin >> t;
    while(t--)cout << solve() << endl;
}
0