結果

問題 No.886 Direct
ユーザー pockynypockyny
提出日時 2019-09-13 23:07:19
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 917 bytes
コンパイル時間 645 ms
コンパイル使用メモリ 74,684 KB
実行使用メモリ 4,848 KB
最終ジャッジ日時 2023-09-17 15:13:57
合計ジャッジ時間 4,216 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,768 KB
testcase_01 AC 2 ms
4,540 KB
testcase_02 AC 3 ms
4,768 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,476 KB
testcase_05 AC 3 ms
4,692 KB
testcase_06 AC 3 ms
4,688 KB
testcase_07 AC 3 ms
4,548 KB
testcase_08 AC 3 ms
4,556 KB
testcase_09 AC 3 ms
4,456 KB
testcase_10 AC 3 ms
4,688 KB
testcase_11 AC 2 ms
4,464 KB
testcase_12 AC 3 ms
4,536 KB
testcase_13 AC 2 ms
4,476 KB
testcase_14 AC 2 ms
4,620 KB
testcase_15 AC 2 ms
4,572 KB
testcase_16 AC 3 ms
4,552 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 AC 2 ms
4,492 KB
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int used[300010];
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<=300000;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) + w*(h - 1)) %= mod;
	cout << ans << endl;
}
0