結果

問題 No.886 Direct
ユーザー pockynypockyny
提出日時 2019-09-23 17:11:18
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 982 bytes
コンパイル時間 755 ms
コンパイル使用メモリ 77,648 KB
実行使用メモリ 74,208 KB
最終ジャッジ日時 2023-10-19 08:12:00
合計ジャッジ時間 10,833 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 4 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 4 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 5 ms
4,348 KB
testcase_22 AC 4 ms
4,348 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 843 ms
74,208 KB
testcase_30 AC 829 ms
74,208 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;
const int MAX = 1000010;
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] -= v[j*i];
			if(v[j]<0) v[j] += mod;
		}
	}
	return v;
}

int main(){
	int i,h,w;
	cin >> h >> w;
	vector<ll> a(max(h,w) + 10),b(max(h,w) + 10);
	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<=max(h,w);i++){
		(a[i] *= b[i]) %= mod;
	}
	b = inv_gcd_trans(a);
	ll ans = 2*b[1]%mod + 2*h*w%mod - h - w;
	while(ans<0) ans += mod;
	cout << ans%mod << endl;
}
0