結果

問題 No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
ユーザー どららどらら
提出日時 2021-01-22 23:48:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,237 bytes
コンパイル時間 1,512 ms
コンパイル使用メモリ 171,656 KB
実行使用メモリ 5,272 KB
最終ジャッジ日時 2023-08-27 23:35:16
合計ジャッジ時間 5,870 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,376 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 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const ll MOD = 1000000007;

ll gcd(ll a, ll b){return (b==0?a:gcd(b,a%b));}
ll extgcd(ll a, ll b, ll &x, ll &y){
  ll d = a;
  if(b!=0){
    d = extgcd(b,a%b,y,x);
    y -= (a/b)*x;
  }else{
    x = 1; y = 0;
  }
  return d;
}

ll calc(ll a, ll b, ll c, ll g, ll x, ll y){

  if(c%g != 0) return 0;
  a /= g;
  b /= g;
  c /= g;

  ll t = c/a;
  ll n = (t - x * c)/b;
  ll m = (- x * c + b-1)/b;
  //cout << c << " " << n << " " << m << endl;
  return max(0LL, n-m+1);
}


void solve(){
  ll N, K, H, Y;
  cin >> N >> K >> H >> Y;

  vector<ll> v{N,K,H};
  sort(ALLOF(v));
  N = v[0];
  K = v[1];
  H = v[2];

  ll x, y;
  ll d = extgcd(N, K, x, y);
  ll g = gcd(N, K);
  
  ll ret = 0;
  for(int z=0; z<=Y/H; z++){
    ll a = N;
    ll b = K;
    ll c = Y-z*H;
    
    ret += calc(a, b, c, g, x, y);
    ret %= MOD;
  }
  cout << ret << endl;
}


int main(){
  int t;
  cin >> t;
  rep(i,t){
    solve();
  }
  
  return 0;
}

0