結果

問題 No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
ユーザー ゆにぽけゆにぽけ
提出日時 2024-02-23 05:23:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 383 ms / 2,000 ms
コード長 1,400 bytes
コンパイル時間 2,762 ms
コンパイル使用メモリ 127,028 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-23 05:23:52
合計ジャッジ時間 5,828 ms
ジャッジサーバーID
(参考情報)
judge16 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 6 ms
6,676 KB
testcase_07 AC 5 ms
6,676 KB
testcase_08 AC 5 ms
6,676 KB
testcase_09 AC 5 ms
6,676 KB
testcase_10 AC 4 ms
6,676 KB
testcase_11 AC 340 ms
6,676 KB
testcase_12 AC 303 ms
6,676 KB
testcase_13 AC 383 ms
6,676 KB
testcase_14 AC 272 ms
6,676 KB
testcase_15 AC 297 ms
6,676 KB
testcase_16 AC 356 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <iterator>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <random>
#include <utility>
#include <functional>
using namespace std;
long long gcd(long long a,long long b,long long &x,long long &y)
{
	x = 1,y = 0;
	long long z = 0,w = 1;
	while(b)
	{
		long long q = a / b;
		a -= q * b; swap(a,b);
		x -= q * z; swap(x,z);
		y -= q * w; swap(y,w);
	}
	return a;
}
void Main()
{
	long long a,b,c,Y;
	cin >> a >> b >> c >> Y;
	if(a < b)
	{
		swap(a,b);
	}
	if(a < c)
	{
		swap(a,c);
	}
	long long y,z;
	long long g = gcd(b,c,y,z);
	b /= g,c /= g;
	const int mod = (int)1e9 + 7;
	long long ans = 0;
	for(int i = 0;a * i <= Y;i++)
	{
		long long Z = Y - a * i;
		if(Z % g)
		{
			continue;
		}
		long long p = y * (Z / g),q = z * (Z / g);
		//b * p + c * q == Z
		q = -q;
		long long L = q >= 0 ? (q + b - 1) / b : -((-q) / b);
		long long U = p >= 0 ? p / c : -((-p + c - 1) / c);
		ans += max(0ll,U - L + 1);
		ans %= mod;
	}
	cout << ans << "\n";
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	cin >> tt;
	while(tt--) Main();
}

0