結果

問題 No.886 Direct
ユーザー pockynypockyny
提出日時 2019-09-23 17:23:16
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 501 ms / 4,000 ms
コード長 945 bytes
コンパイル時間 791 ms
コンパイル使用メモリ 77,640 KB
実行使用メモリ 74,216 KB
最終ジャッジ日時 2023-10-19 08:12:40
合計ジャッジ時間 19,501 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 473 ms
74,216 KB
testcase_01 AC 465 ms
74,216 KB
testcase_02 AC 474 ms
74,216 KB
testcase_03 AC 466 ms
74,216 KB
testcase_04 AC 464 ms
74,216 KB
testcase_05 AC 465 ms
74,216 KB
testcase_06 AC 452 ms
74,216 KB
testcase_07 AC 470 ms
74,216 KB
testcase_08 AC 467 ms
74,216 KB
testcase_09 AC 469 ms
74,216 KB
testcase_10 AC 470 ms
74,216 KB
testcase_11 AC 464 ms
74,216 KB
testcase_12 AC 472 ms
74,216 KB
testcase_13 AC 472 ms
74,216 KB
testcase_14 AC 474 ms
74,216 KB
testcase_15 AC 469 ms
74,216 KB
testcase_16 AC 464 ms
74,216 KB
testcase_17 AC 474 ms
74,216 KB
testcase_18 AC 475 ms
74,216 KB
testcase_19 AC 501 ms
74,216 KB
testcase_20 AC 477 ms
74,216 KB
testcase_21 AC 484 ms
74,216 KB
testcase_22 AC 490 ms
74,216 KB
testcase_23 AC 484 ms
74,216 KB
testcase_24 AC 476 ms
74,216 KB
testcase_25 AC 473 ms
74,216 KB
testcase_26 AC 470 ms
74,216 KB
testcase_27 AC 469 ms
74,216 KB
testcase_28 AC 468 ms
74,216 KB
testcase_29 AC 468 ms
74,216 KB
testcase_30 AC 468 ms
74,216 KB
testcase_31 AC 477 ms
74,216 KB
testcase_32 AC 477 ms
74,216 KB
testcase_33 AC 470 ms
74,216 KB
testcase_34 AC 465 ms
74,216 KB
testcase_35 AC 466 ms
74,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;
const int MAX = 1000010;
constexpr ll mod = 1000000007;
vector<ll> gcd_trans(vector<ll> &v){
	int i,j,n = v.size();
	vector<bool> used(n,true);
	for(i=2;i<n;i++){
		if(!used[i]) continue;
		for(j=(n - 1)/i;j>=1;j--){
			used[j*i] = false;
			(v[j] += v[j*i]) %= mod;
		}
	}
	return v;
}

vector<ll> inv_gcd_trans(vector<ll> &v){
	int i,j,n = v.size();
	vector<bool> used(n,true);
	for(i=2;i<n;i++){
		if(!used[i]) continue;
		for(j=1;j*i<n;j++){
			used[j*i] = false;
			(v[j] += mod - v[j*i]) %= mod;
		}
	}
	return v;
}
vector<ll> a(3*MAX),b(3*MAX);
int main(){
	ll i,h,w;
	cin >> h >> w;
	for(i=1;i<h;i++){
		a[i] = h - i;
	}
	for(i=1;i<w;i++){
		b[i] = w - i;
	}
	a = gcd_trans(a),b = gcd_trans(b);
	for(i=0;i<a.size();i++){
		(a[i] *= b[i]) %= mod;
	}
	b = inv_gcd_trans(a);
	ll ans = (2*b[1]%mod + h*(w - 1)%mod + w*(h - 1)%mod)%mod;
	cout << ans << endl;
}
0