結果

問題 No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
ユーザー kotatsugamekotatsugame
提出日時 2021-01-30 14:01:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 382 ms / 2,000 ms
コード長 2,838 bytes
コンパイル時間 995 ms
コンパイル使用メモリ 70,780 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 10:33:25
合計ジャッジ時間 3,849 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 5 ms
4,380 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 340 ms
4,380 KB
testcase_12 AC 299 ms
4,376 KB
testcase_13 AC 382 ms
4,376 KB
testcase_14 AC 271 ms
4,376 KB
testcase_15 AC 297 ms
4,376 KB
testcase_16 AC 360 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
a.cpp:9:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]

ソースコード

diff #

#line 1 "a.cpp"
#include<iostream>
#include<algorithm>
using namespace std;
#line 1 "/home/kotatsugame/library/math/extgcd.cpp"
template<typename T>
T extgcd(T a,T b,T&x,T&y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	T q=a/b;
	T g=extgcd(b,a-q*b,y,x);
	y-=q*x;
	return g;
}
#line 3 "/home/kotatsugame/library/math/modint.cpp"
#include<utility>
template<int m>
struct modint{
	unsigned int x;
	constexpr modint()noexcept:x(){}
	template<typename T>
	constexpr modint(T x_)noexcept:x((x_%=m)<0?x_+m:x_){}
	constexpr unsigned int val()const noexcept{return x;}
	constexpr modint&operator++()noexcept{if(++x==m)x=0;return*this;}
	constexpr modint&operator--()noexcept{if(x==0)x=m;--x;return*this;}
	constexpr modint operator++(int)noexcept{modint res=*this;++*this;return res;}
	constexpr modint operator--(int)noexcept{modint res=*this;--*this;return res;}
	constexpr modint&operator+=(const modint&a)noexcept{x+=a.x;if(x>=m)x-=m;return*this;}
	constexpr modint&operator-=(const modint&a)noexcept{if(x<a.x)x+=m;x-=a.x;return*this;}
	constexpr modint&operator*=(const modint&a)noexcept{x=(unsigned long long)x*a.x%m;return*this;}
	constexpr modint&operator/=(const modint&a)noexcept{return*this*=a.inv();}
	constexpr modint operator+()const noexcept{return*this;}
	constexpr modint operator-()const noexcept{return modint()-*this;}
	constexpr modint pow(long long n)const noexcept
	{
		if(n<0)return pow(-n).inv();
		modint x=*this,r=1;
		for(;n;x*=x,n>>=1)if(n&1)r*=x;
		return r;
	}
	constexpr modint inv()const noexcept
	{
		int s=x,t=m,x=1,u=0;
		while(t)
		{
			int k=s/t;
			s-=k*t;
			swap(s,t);
			x-=k*u;
			swap(x,u);
		}
		return modint(x);
	}
	friend constexpr modint operator+(const modint&a,const modint&b){return modint(a)+=b;}
	friend constexpr modint operator-(const modint&a,const modint&b){return modint(a)-=b;}
	friend constexpr modint operator*(const modint&a,const modint&b){return modint(a)*=b;}
	friend constexpr modint operator/(const modint&a,const modint&b){return modint(a)/=b;}
	friend constexpr bool operator==(const modint&a,const modint&b){return a.x==b.x;}
	friend constexpr bool operator!=(const modint&a,const modint&b){return a.x!=b.x;}
	friend ostream&operator<<(ostream&os,const modint&a){return os<<a.x;}
	friend istream&operator>>(istream&is,modint&a){long long v;is>>v;a=modint(v);return is;}
};
#line 6 "a.cpp"
using mint=modint<(int)1e9+7>;
int T;
long A[3],Y;
main()
{
	cin>>T;
	for(;T--;)
	{
		cin>>A[0]>>A[1]>>A[2]>>Y;
		sort(A,A+3);
		mint ans=0;
		long x,y;
		long g=extgcd(A[0],A[1],x,y);
		long a=A[0]/g,b=A[1]/g;
		for(;Y>=0;Y-=A[2])
		{
			if(Y%g!=0)continue;
			long nx=Y/g*x,ny=Y/g*y;
			if(nx>=ny)
			{
				long L=(-ny+a-1)/a;
				long R=nx/b;
				if(L<=R)ans+=R-L+1;
			}
			else
			{
				long L=(-nx+b-1)/b;
				long R=ny/a;
				if(L<=R)ans+=R-L+1;
			}
		}
		cout<<ans<<endl;
	}
}
0