結果

問題 No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
ユーザー umezoumezo
提出日時 2021-01-22 23:52:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 793 bytes
コンパイル時間 1,929 ms
コンパイル使用メモリ 199,564 KB
実行使用メモリ 8,880 KB
最終ジャッジ日時 2023-08-28 08:47:16
合計ジャッジ時間 6,074 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
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 #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

const int MOD=1e9+7;

ll extGCD(ll a,ll b,ll &x,ll &y){
  if(b==0){
    x=1;
    y=0;
    return a;
  }
  ll d=extGCD(b,a%b,y,x);
  y-=a/b*x;
  return d;
}

int main(){
  int t;
  cin>>t;
  
  while(t--){
    ll n,k,h,y;
    cin>>n>>k>>h>>y;
    
    if(n>h) swap(n,h);
    if(k>h) swap(k,h);
    if(n>k) swap(n,k);
    
    ll ans=0;
    for(int i=0;i<=y/h;i++){
      ll r=(y-h*i)/gcd(n,k);
      ll a=n/gcd(n,k);
      ll b=k/gcd(n,k);
      
      ll p,q;
      if(extGCD(a,b,p,q)<0) p=-p,q=-q;
      p*=r,q*=r;
      if(q/a<-p/b) continue;
      ans=(ans+p/b+q/a)%MOD;
      if(p%b==0) ans++;
    }
    cout<<ans<<endl;
  }
  
  return 0;
}
0