結果

問題 No.886 Direct
ユーザー pockynypockyny
提出日時 2019-09-13 23:32:13
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3,342 ms / 4,000 ms
コード長 901 bytes
コンパイル時間 624 ms
コンパイル使用メモリ 75,424 KB
実行使用メモリ 15,360 KB
最終ジャッジ日時 2023-09-17 15:26:28
合計ジャッジ時間 31,084 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
15,260 KB
testcase_01 AC 6 ms
15,096 KB
testcase_02 AC 6 ms
15,100 KB
testcase_03 AC 17 ms
15,044 KB
testcase_04 AC 7 ms
15,092 KB
testcase_05 AC 6 ms
15,336 KB
testcase_06 AC 6 ms
15,068 KB
testcase_07 AC 6 ms
15,076 KB
testcase_08 AC 6 ms
15,048 KB
testcase_09 AC 6 ms
15,260 KB
testcase_10 AC 7 ms
15,040 KB
testcase_11 AC 7 ms
15,200 KB
testcase_12 AC 7 ms
15,076 KB
testcase_13 AC 6 ms
15,264 KB
testcase_14 AC 7 ms
15,072 KB
testcase_15 AC 6 ms
15,036 KB
testcase_16 AC 6 ms
15,088 KB
testcase_17 AC 19 ms
15,360 KB
testcase_18 AC 20 ms
15,128 KB
testcase_19 AC 20 ms
15,148 KB
testcase_20 AC 13 ms
15,064 KB
testcase_21 AC 8 ms
15,260 KB
testcase_22 AC 23 ms
15,208 KB
testcase_23 AC 1,482 ms
15,040 KB
testcase_24 AC 1,028 ms
15,044 KB
testcase_25 AC 373 ms
15,092 KB
testcase_26 AC 1,308 ms
15,072 KB
testcase_27 AC 1,798 ms
15,152 KB
testcase_28 AC 2,956 ms
15,032 KB
testcase_29 AC 3,266 ms
15,216 KB
testcase_30 AC 6 ms
15,336 KB
testcase_31 AC 3,329 ms
15,320 KB
testcase_32 AC 3,336 ms
15,120 KB
testcase_33 AC 3,338 ms
15,044 KB
testcase_34 AC 3,334 ms
15,092 KB
testcase_35 AC 3,342 ms
15,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int used[3000010];
ll ans = 0,mod = 1000000007,h,w;
ll inv = (mod + 1)/2;
void solve(int x){
	int y = x;
	vector<int> fac;
	while(y!=1){
		int k = used[y];
		fac.push_back(k);
		while(y%k==0 && y!=1){
			y /= k;
		}
	}
	int i,j,s = fac.size();
	ll num = 0,sum = 0;
	for(i=0;i<(1<<s);i++){
		ll z = 1,sig = 1;
		for(j=0;j<s;j++){
			if((1<<j) & i){
				z *= fac[j];
				sig *= -1;
			}
		}
		ll y = w/z;
		num += sig*y;
		(sum += (sig*(z*y%mod*(y + 1)%mod*inv%mod) + mod)%mod) %= mod;
	}
	(ans += (h - x)*((w*num - sum + mod)%mod)) %= mod;
}

int main(){
	int i,j;
	cin >> h >> w;
	for(i=1;i<=3000000;i++){
		used[i] = -1;
	}
	for(i=2;i<h;i++){
		for(j=i;j<h;j+=i){
			if(used[j]==-1) used[j] = i;
		}
	}
	for(i=1;i<h;i++){
		solve(i);
	}
	ans *= 2;
	(ans += h*(w - 1)%mod + w*(h - 1)%mod) %= mod;
	cout << ans << endl;
}
0