結果

問題 No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
ユーザー ttkkggwwttkkggww
提出日時 2021-01-22 23:59:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,090 bytes
コンパイル時間 4,063 ms
コンパイル使用メモリ 262,632 KB
実行使用メモリ 7,996 KB
最終ジャッジ日時 2023-08-28 08:56:44
合計ジャッジ時間 8,209 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace atcoder;
using namespace std;
using ll = long long;
using mint = modint1000000007;
long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}
int main(){
	int t = 1;
	cin >> t;
	while(t--){
		ll N,K,H,Y;
		cin >> N >> K >> H >> Y;
		vector<ll> A={N,K,H};
		sort(A.begin(),A.end(),greater<>());
		ll x,y;
		mint ans = 0;
		for(ll i = 0;i*A[0]<=Y;i++){
			if(i*A[0]==Y){ans++;continue;}
			ll gcd = extGCD(A[1],A[2],x,y);
			if((Y-i*A[0])%gcd!=0)continue;
			x *= (Y-i*A[0])/gcd;y *= (Y-i*A[0])/gcd;
			//X = x + A2 * t;
			//Y = y - A1 * t;
			ll A1 = A[1]/gcd,A2 = A[2]/gcd;
			ll X = -x/A2,Y = y/A1;
			//while(x+A2*X<0)X++;
			ll l = INT_MIN,r= INT_MAX;
			while(r-l>1){
				ll m = (l+r)/2;
				if(y-A1*m<0)r = m;
				else l = m;
			}
			//cout<<l<<' '<<r<<endl;
			//if(y-A1*Y<0)
			Y = l;
			if(Y-X<0)continue;
			ans += Y-X+1;

		}
		cout<<ans.val()<<endl;

	}
}
0