結果
| 問題 |
No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
|
| コンテスト | |
| ユーザー |
ゆにぽけ
|
| 提出日時 | 2024-02-23 05:22:29 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,340 bytes |
| コンパイル時間 | 1,360 ms |
| コンパイル使用メモリ | 123,112 KB |
| 最終ジャッジ日時 | 2025-02-19 19:02:13 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 TLE * 1 |
ソースコード
#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;
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();
}
ゆにぽけ