0.1s不可战胜的,求卡常(悬关)
查看原帖
0.1s不可战胜的,求卡常(悬关)
704668
WZWZWZWY楼主2024/12/15 19:48

差0.1s求卡常qwq

#include <bits/stdc++.h> // https://www.luogu.com.cn/article/ys6i6v48
#define int long long
using namespace std;

const int N = 1e6 + 5, mod = 998244353;

int a[N], n, m;

inline int cnt(int &R, int l, int r) {
	int R2 = R;
	R = upper_bound(a + R, a + 1 + n, r) - a;
	return max(0ll, (int)(upper_bound(a + R2, a + 1 + n, r) - a) -
	 (lower_bound(a + R2, a + 1 + n, l) - a));
}

int f(int x) {
	int l = 1, r, res = 0, R = 1;
	while (l <= x) {
		r = x / (x / l);
		(res += (x / r) * cnt(R, l, r) % mod) %= mod;
		l = r + 1;
	}
	return res;
}

inline int read() {
	int p = 0; char c = getchar();
	while (c < '0' && c > '9') c = getchar();
	while (c >= '0' && c <= '9') {
		p = p * 10 + c - '0';
		c = getchar();
	}
	return p;
}

signed main() {
	//cin.tie(0); ios::sync_with_stdio(0);
	n = read(); m = read();
	for (int i = 1; i <= n; i++) a[i] = read();
	sort(a + 1, a + 1 + n);
	int ans = 0;
	for (int i = 1; i <= n; ) {
		int p = f(m / a[i]);
		int k = m / a[i];
		while (i <= n && m / a[i] == k) {
			(ans += p) %= mod;
			i ++;
		}
	}
		
	cout << ans;
}
2024/12/15 19:48
加载中...