結果

問題 No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2021-01-22 23:10:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 547 ms / 2,000 ms
コード長 882 bytes
コンパイル時間 808 ms
コンパイル使用メモリ 81,976 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-27 22:08:39
合計ジャッジ時間 4,631 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 8 ms
4,376 KB
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 6 ms
4,384 KB
testcase_09 AC 6 ms
4,376 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 457 ms
4,376 KB
testcase_12 AC 393 ms
4,380 KB
testcase_13 AC 517 ms
4,376 KB
testcase_14 AC 360 ms
4,376 KB
testcase_15 AC 415 ms
4,376 KB
testcase_16 AC 547 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<algorithm>
#include<cassert>
#include<iostream>
#include<vector>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef vector<lint>vl;
typedef pair<int,int>pii;
#define rep(i,n)for(int i=0;i<(int)(n);++i)

lint gcd(lint x,lint y,lint&a,lint&b){
  if(y==0){
    a=1,b=0;
    return x;
  }
  lint q=x/y;
  lint g=gcd(y,x-q*y,b,a);
  b-=q*a;
  return g;
}

int main(){
  int t;cin>>t;
  while(t--){
    lint y;vl a(3);
    rep(i,3)cin>>a[i];
    cin>>y;
    sort(a.rbegin(),a.rend());
    lint ans=0;
    lint d,e;
    lint g=gcd(a[1],a[2],d,e);
    a[1]/=g;
    a[2]/=g;
    d%=a[2];
    if(d<0)d+=a[2];
    for(lint i=0;i<=y/a[0];i++){
      lint c=y-a[0]*i;
      if(c%g)continue;
      c/=g;
      lint x=d*c%a[2];
      if(c<x*a[1])continue;
      lint f=(c-x*a[1])/a[1]/a[2];
      ans+=f+1;
      ans%=1000000007;
    }
    cout<<ans<<endl;
  }
}
0