結果

問題 No.886 Direct
ユーザー pockynypockyny
提出日時 2019-09-13 23:06:40
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 915 bytes
コンパイル時間 613 ms
コンパイル使用メモリ 73,892 KB
実行使用メモリ 13,188 KB
最終ジャッジ日時 2023-09-17 15:13:41
合計ジャッジ時間 11,066 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘ll solve(int)’ 内:
main.cpp:34:1: 警告: 非 void を戻す関数内に return 文がありません [-Wreturn-type]
   34 | }
      | ^

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int used[300010];
ll ans = 0,mod = 1000000007,h,w;
ll 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