結果

問題 No.886 Direct
ユーザー pockynypockyny
提出日時 2019-09-13 23:08:49
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 927 bytes
コンパイル時間 601 ms
コンパイル使用メモリ 73,908 KB
実行使用メモリ 15,344 KB
最終ジャッジ日時 2023-09-17 15:16:02
合計ジャッジ時間 6,131 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
15,296 KB
testcase_01 AC 6 ms
15,020 KB
testcase_02 AC 6 ms
15,172 KB
testcase_03 WA -
testcase_04 AC 6 ms
15,216 KB
testcase_05 AC 6 ms
15,100 KB
testcase_06 AC 6 ms
15,040 KB
testcase_07 AC 7 ms
15,212 KB
testcase_08 AC 6 ms
15,016 KB
testcase_09 AC 6 ms
15,028 KB
testcase_10 AC 6 ms
15,036 KB
testcase_11 AC 6 ms
15,024 KB
testcase_12 AC 6 ms
15,104 KB
testcase_13 AC 6 ms
15,028 KB
testcase_14 AC 6 ms
15,220 KB
testcase_15 AC 6 ms
15,196 KB
testcase_16 AC 7 ms
15,136 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 467 ms
15,104 KB
testcase_30 AC 6 ms
15,036 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;
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*(y + 1)/2;
	}
	/*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) break;;
			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