結果

問題 No.1201 お菓子配り-4
ユーザー kotatsugamekotatsugame
提出日時 2021-01-11 06:25:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,474 ms / 4,000 ms
コード長 2,471 bytes
コンパイル時間 649 ms
コンパイル使用メモリ 65,880 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 06:43:07
合計ジャッジ時間 10,924 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
6,816 KB
testcase_01 AC 351 ms
6,940 KB
testcase_02 AC 507 ms
6,940 KB
testcase_03 AC 246 ms
6,940 KB
testcase_04 AC 121 ms
6,940 KB
testcase_05 AC 298 ms
6,944 KB
testcase_06 AC 46 ms
6,940 KB
testcase_07 AC 136 ms
6,944 KB
testcase_08 AC 377 ms
6,944 KB
testcase_09 AC 278 ms
6,944 KB
testcase_10 AC 4 ms
6,940 KB
testcase_11 AC 73 ms
6,944 KB
testcase_12 AC 574 ms
6,940 KB
testcase_13 AC 17 ms
6,940 KB
testcase_14 AC 9 ms
6,940 KB
testcase_15 AC 451 ms
6,940 KB
testcase_16 AC 139 ms
6,940 KB
testcase_17 AC 179 ms
6,940 KB
testcase_18 AC 30 ms
6,940 KB
testcase_19 AC 29 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 1 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 1 ms
6,940 KB
testcase_30 AC 726 ms
6,944 KB
testcase_31 AC 730 ms
6,940 KB
testcase_32 AC 728 ms
6,940 KB
testcase_33 AC 728 ms
6,940 KB
testcase_34 AC 725 ms
6,944 KB
testcase_35 AC 1,474 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
a.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]

ソースコード

diff #

#line 1 "a.cpp"
#include<iostream>
using namespace std;
#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 4 "a.cpp"
using mint=modint<(int)1e9+7>;
int N,M,A[2020],B[2020];
int gcd(int a,int b){return b?gcd(b,a%b):a;}
main()
{
	cin>>N>>M;
	for(int i=0;i<N;i++)cin>>A[i];
	for(int j=0;j<M;j++)cin>>B[j];
	mint ans=0;
	for(int i=0;i<N;i++)for(int j=0;j<M;j++)
	{
		int g=gcd(A[i],B[j]);
		ans+=mint(A[i]+1)*mint(B[j]+1)+g+1-2*(B[j]+1);
	}
	cout<<ans<<endl;
}
0