QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#796122#9553. The Hermitlew2018WA 1304ms5992kbC++141.5kb2024-12-01 12:18:422024-12-01 12:18:42

Judging History

你现在查看的是最新测评结果

  • [2024-12-01 12:18:42]
  • 评测
  • 测评结果:WA
  • 用时:1304ms
  • 内存:5992kb
  • [2024-12-01 12:18:42]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define For(i, a, b) for (int i = (a); i <= (b); i++)
#define FOR(i, a, b) for (int i = (a); i >= (b); i--)
#define int long long

const int N = 1e5 + 5;
const int mod = 998244353;
int n, m, cnt[N];
ll fac[N], inv[N], ans;

int qpow(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1) res = (ll)res * a % mod;
		a = (ll)a * a % mod;
		b >>= 1;
	}
	return res;
}

// m个数里选n个
ll c(int m, int n) {
	if (n == m) return 1;
	if (n > m || n < 0) return 0;
	return (fac[m] * inv[n] % mod * inv[m - n] % mod) % mod;
}

void dfs(int u, int len) {
	//cout << "u = " << u << " len = " << len << endl;
	if (len == n) {
		ans -= 1;
		return;
	}
	(ans -= c(cnt[u] - 1, n - len)) %= mod;
	for (int j = 2 * u; j <= m; j += u) {
		dfs(j, len + 1);
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> m >> n;
	fac[0] = 1;
	For (i, 1, m) {
		fac[i] = (ll)fac[i - 1] * i % mod;
		inv[i] = qpow(fac[i], mod - 2); 
	}
	For (i, 1, n) {
		int tot = 0;
		for (int j = i; j <= m; j += i) tot++;
		cnt[i] = tot;
	}
	ans = c(m, n) * n % mod;
	// 枚举删的第一个数
	for (int i = 1; i <= m; i++) {
		(ans -= c(cnt[i] - 1, n - 1)) %= mod;
		// 枚举删的第二个数
		for (int j = 2 * i; j <= m; j += i) {
			dfs(j, 2);
		}
	}
	cout << (ans + mod) % mod << endl;
	return 0;
}   

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3648kb

input:

4 3

output:

7

result:

ok 1 number(s): "7"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

11 4

output:

1187

result:

ok 1 number(s): "1187"

Test #3:

score: 0
Accepted
time: 1304ms
memory: 5992kb

input:

100000 99999

output:

17356471

result:

ok 1 number(s): "17356471"

Test #4:

score: 0
Accepted
time: 32ms
memory: 3852kb

input:

11451 1919

output:

845616153

result:

ok 1 number(s): "845616153"

Test #5:

score: 0
Accepted
time: 1303ms
memory: 5220kb

input:

99998 12345

output:

936396560

result:

ok 1 number(s): "936396560"

Test #6:

score: -100
Wrong Answer
time: 1299ms
memory: 5224kb

input:

100000 1

output:

997277603

result:

wrong answer 1st numbers differ - expected: '0', found: '997277603'