結果

問題 No.886 Direct
ユーザー ianCKianCK
提出日時 2020-01-01 04:32:18
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,326 bytes
コンパイル時間 1,467 ms
コンパイル使用メモリ 40,656 KB
実行使用メモリ 26,932 KB
最終ジャッジ日時 2023-08-13 11:50:36
合計ジャッジ時間 4,320 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
26,820 KB
testcase_01 AC 34 ms
26,852 KB
testcase_02 AC 35 ms
26,796 KB
testcase_03 AC 35 ms
26,784 KB
testcase_04 AC 35 ms
26,868 KB
testcase_05 AC 36 ms
26,796 KB
testcase_06 AC 36 ms
26,856 KB
testcase_07 AC 35 ms
26,852 KB
testcase_08 AC 34 ms
26,780 KB
testcase_09 AC 34 ms
26,848 KB
testcase_10 AC 35 ms
26,860 KB
testcase_11 AC 36 ms
26,888 KB
testcase_12 AC 35 ms
26,816 KB
testcase_13 AC 35 ms
26,788 KB
testcase_14 AC 35 ms
26,892 KB
testcase_15 AC 36 ms
26,856 KB
testcase_16 AC 35 ms
26,860 KB
testcase_17 AC 35 ms
26,860 KB
testcase_18 AC 35 ms
26,844 KB
testcase_19 AC 36 ms
26,788 KB
testcase_20 AC 36 ms
26,812 KB
testcase_21 AC 35 ms
26,880 KB
testcase_22 AC 36 ms
26,796 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 82 ms
26,800 KB
testcase_30 AC 35 ms
26,836 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <vector>
using namespace std;
typedef long long int ll;

#define PB push_back
constexpr int kMod = int(1E9 + 7), kN = int(3E6 + 10);

int ABS(int n) {return n >= 0 ? n : -n;}
int gcd(int a, int b) {return  b ? gcd(b, a % b) : a;}

ll Pow(ll a, ll b) {
	ll ans = 1;
	while (b) {
		if (b & 1) ans = ans * a % kMod;
		a = a * a % kMod;
		b >>= 1;
	}
	return ans;
}
ll Rev(ll n) {return Pow(n, kMod - 2);}

ll mu[kN];

void pre() {
	mu[0] = 0;
	mu[1] = 1;
	vector<int> prime;
	for (int i = 2; i < kN; i++) mu[i] = -3;
	for (int i = 2; i < kN; i++) {
		if (mu[i] == -3) {
			mu[i] = -1;
			prime.PB(i);
		}
		for (int j : prime) {
			if (i * j >= kN) break;
			if (i % j == 0) {
				mu[i * j] = 0;
				break;
			}
			else mu[i * j] = -mu[i];
		}
	}
	return ;
}

int main() {
	pre();
	int n, m;
	ll ans = 0, l, r;
	scanf("%d%d", &n, &m);
	for (int d = 1; d < n; d++) {
		l = -(((n - 1) / d) * ((n - 1) / d + 1)) / 2;
		r = -(((m - 1) / d) * ((m - 1) / d + 1)) / 2;
		l *= d;
		r *= d;
		l += n * ((n - 1) / d);
		r += m * ((m - 1) / d);
		l %= kMod;
		r %= kMod;
		ans += l * r * mu[d] % kMod;
	}
	ans = ans * 2 % kMod;
	if (ans < 0) ans += kMod;
	ans += (n - 1) * m % kMod + (m - 1) * n % kMod;
	ans %= kMod;
	printf("%lld\n", ans);
}
0