結果

問題 No.886 Direct
ユーザー pockynypockyny
提出日時 2019-09-13 23:19:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 970 bytes
コンパイル時間 594 ms
コンパイル使用メモリ 75,580 KB
実行使用メモリ 15,364 KB
最終ジャッジ日時 2023-09-17 15:21:26
合計ジャッジ時間 26,836 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
15,024 KB
testcase_01 AC 6 ms
15,040 KB
testcase_02 AC 6 ms
15,204 KB
testcase_03 AC 15 ms
15,040 KB
testcase_04 AC 7 ms
15,160 KB
testcase_05 AC 6 ms
15,044 KB
testcase_06 AC 7 ms
15,256 KB
testcase_07 AC 6 ms
15,020 KB
testcase_08 AC 7 ms
15,300 KB
testcase_09 AC 7 ms
15,076 KB
testcase_10 AC 6 ms
15,312 KB
testcase_11 AC 7 ms
15,032 KB
testcase_12 AC 7 ms
15,036 KB
testcase_13 AC 6 ms
15,020 KB
testcase_14 AC 6 ms
15,100 KB
testcase_15 AC 6 ms
15,020 KB
testcase_16 AC 6 ms
15,032 KB
testcase_17 AC 17 ms
15,120 KB
testcase_18 AC 17 ms
15,116 KB
testcase_19 AC 18 ms
15,180 KB
testcase_20 AC 12 ms
15,120 KB
testcase_21 AC 8 ms
15,020 KB
testcase_22 AC 20 ms
15,036 KB
testcase_23 AC 1,264 ms
15,108 KB
testcase_24 AC 877 ms
15,040 KB
testcase_25 AC 319 ms
15,036 KB
testcase_26 AC 1,114 ms
15,300 KB
testcase_27 WA -
testcase_28 AC 2,538 ms
15,032 KB
testcase_29 AC 2,798 ms
15,256 KB
testcase_30 AC 6 ms
15,072 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;
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;
	}
	//cout << x << endl;
	//cout << num << " " << sum << endl;
	(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;
	}
	used[1] = 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