結果

問題 No.2128 Round up!!
ユーザー 沙耶花沙耶花
提出日時 2022-11-18 22:10:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 926 bytes
コンパイル時間 4,406 ms
コンパイル使用メモリ 261,532 KB
実行使用メモリ 960,112 KB
最終ジャッジ日時 2023-10-20 06:59:37
合計ジャッジ時間 9,033 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001

mint get(long long a,long long b,long long c){
	long long g = gcd(b,c);
	a /= g;
	b /= g;
	c /= g;
	//cout<<a<<','<<b<<','<<c<<endl;
	if(a/b==c)return 0;
	if(b>c){
		mint ret = c;
		ret -= a/b;
		ret *= 2;
		return ret;
		
	}
	else{
		return get(((a+c-1)/c)*c,c,b) + 1;
	}
}

int main(){
	
	int _t;
	cin>>_t;
	
	rep(_,_t){
		
		long long a,b,c;
		cin>>a>>b>>c;
		
		if(a%b==0&&a%c==0){
			cout<<1<<endl;
			continue;
		}
		
		mint ans = 0;
		ans += 1;
		
		long long x = ((a+b-1)/b)*b;
		long long y = ((a+c-1)/c)*c;
		if(x<=y){
			if(x!=a)ans++;
			ans += get(x,b,c);
		}
		else{
			if(y!=a)ans++;
			ans += get(y,c,b);
		}
		
		cout<<ans.val()<<endl;
		
	}
	
	
	return 0;
}
0