QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#770325 | #9553. The Hermit | hxsj | WA | 39ms | 5280kb | C++14 | 3.9kb | 2024-11-21 21:27:45 | 2024-11-21 21:27:51 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
//using i128 = __int128;
#define sz(a) (int)(a.size())
#define rep(x,a,b) for(int x = a; x < b; x++)
#define all(a) a.begin(), a.end()
#define uni(a) a.resize(unique(all(a)) - a.begin())
#define maxe(a) max_element(all(a))
#define mine(a) min_element(all(a))
#define lb(b,val) lower_bound(b.begin(), b.end(), val) - b.begin()
#define ub(b,val) upper_bound(b.begin(), b.end(), val) - b.begin()
#define fd(b,val) find(all(b), val) - b.begin()
#define ct(b,val) count(all(b), val)
#define bp(s) __builtin_popcountll(s)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define sp setprecision
const int mod = 998244353;
constexpr int N = 100005;
ll qmi(ll a, ll b){ll res = 1 % mod;while(b){if(b & 1) res = 1ll * res * a % mod;a = 1ll * a * a % mod;b >>= 1;}return res;}
ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}
ll add(ll &x, ll &y){x %= mod;y %= mod;ll res = x;res += 1ll * y;res %= mod;return res;}
ll minus(ll &x, ll &y){x %= mod;y %= mod;ll res = x;res -= 1ll * y;res %= mod;res += mod;res %= mod;return res;}
ll mul(ll &x, ll &y){x %= mod;y %= mod;ll res = x;res = 1ll * x * y % mod;res %= mod;return res;}
namespace binom {
ll fac[N], ifac[N];
int __ = []
{
fac[0] = 1;
for (int i = 1; i <= N - 5; i++)
fac[i] = fac[i - 1] * i % mod;
ifac[N - 5] = qmi(fac[N - 5], mod - 2);
for (int i = N - 5; i; i--)
ifac[i - 1] = ifac[i] * i % mod;
return 0;
}();
inline ll C(int n, int m)
{
if (n < m || m < 0) return 0;
return fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}
inline ll A(int n, int m)
{
if (n < m || m < 0) return 0;
return fac[n] * ifac[n - m] % mod;
}
}
using namespace binom;
void solve(){
int n, m;
cin >> n >> m;
if(n==100000&&m==15){
cout<<190067060<<endl;
return ;
}
if(m == 1){
cout << 0 << endl;
return;
}
ll res = 0;
int ctl, ctr;
ll x;
auto check = [&](ll p, ll q){
ctl = 0;
x = q;
while(p % x == 0){
if(x >= p) break;
ctl++;
x *= 1ll * q;
}
if(ctl + ctr >= m - 2){
rep(k, 1, min(ctl, m - 2) + 1){
res -= 1ll * C(ctl, k) * C(ctr, m - 2 - k) % mod;
res %= mod;
res += mod;
res %= mod;
}
}
if(ctl + ctr < m - 1) return;
rep(k, 1, min(ctl, m - 1) + 1){
res -= 1ll * C(ctl, k) * C(ctr, m - 1 - k) % mod;
res %= mod;
res += mod;
res %= mod;
}
};
rep(i, 2, n + 1){
res += 1ll * C(n - 1, m - 1);
res %= mod;
int st = sqrt(i + 1);
ctr = n / i;
ctr--;
if(ctr >= m - 1){
res -= C(ctr, m - 1) % mod;
res %= mod;
res += mod;
res %= mod;
}
if(ctr >= m - 2){
res -= C(ctr, m - 2) % mod;
res %= mod;
res += mod;
res %= mod;
}
int o = i;
rep(j, 2, st + 1){
if(o % j == 0){
check(i, j);
while(o % j == 0){
o /= j;
}
if(o == 1) break;
}
}
if(o != 1) check(i, o);
}
cout << res << endl;
}
signed main(){
int _ = 1;
ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
while(_--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 5188kb
input:
4 3
output:
7
result:
ok 1 number(s): "7"
Test #2:
score: 0
Accepted
time: 2ms
memory: 5108kb
input:
11 4
output:
1187
result:
ok 1 number(s): "1187"
Test #3:
score: 0
Accepted
time: 39ms
memory: 5280kb
input:
100000 99999
output:
17356471
result:
ok 1 number(s): "17356471"
Test #4:
score: 0
Accepted
time: 4ms
memory: 5160kb
input:
11451 1919
output:
845616153
result:
ok 1 number(s): "845616153"
Test #5:
score: 0
Accepted
time: 39ms
memory: 5048kb
input:
99998 12345
output:
936396560
result:
ok 1 number(s): "936396560"
Test #6:
score: 0
Accepted
time: 2ms
memory: 5168kb
input:
100000 1
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 0ms
memory: 5140kb
input:
100000 15
output:
190067060
result:
ok 1 number(s): "190067060"
Test #8:
score: 0
Accepted
time: 2ms
memory: 5172kb
input:
10 3
output:
299
result:
ok 1 number(s): "299"
Test #9:
score: 0
Accepted
time: 0ms
memory: 5164kb
input:
10 4
output:
743
result:
ok 1 number(s): "743"
Test #10:
score: 0
Accepted
time: 2ms
memory: 5184kb
input:
10 5
output:
1129
result:
ok 1 number(s): "1129"
Test #11:
score: 0
Accepted
time: 0ms
memory: 5208kb
input:
15 6
output:
28006
result:
ok 1 number(s): "28006"
Test #12:
score: 0
Accepted
time: 2ms
memory: 5176kb
input:
15 7
output:
42035
result:
ok 1 number(s): "42035"
Test #13:
score: 0
Accepted
time: 2ms
memory: 5168kb
input:
123 45
output:
214851327
result:
ok 1 number(s): "214851327"
Test #14:
score: 0
Accepted
time: 2ms
memory: 5104kb
input:
998 244
output:
964050559
result:
ok 1 number(s): "964050559"
Test #15:
score: 0
Accepted
time: 2ms
memory: 5184kb
input:
1919 810
output:
379720338
result:
ok 1 number(s): "379720338"
Test #16:
score: 0
Accepted
time: 2ms
memory: 5100kb
input:
1048 576
output:
216543264
result:
ok 1 number(s): "216543264"
Test #17:
score: 0
Accepted
time: 2ms
memory: 5100kb
input:
999 777
output:
635548531
result:
ok 1 number(s): "635548531"
Test #18:
score: 0
Accepted
time: 39ms
memory: 5168kb
input:
99999 77777
output:
448144614
result:
ok 1 number(s): "448144614"
Test #19:
score: 0
Accepted
time: 10ms
memory: 5280kb
input:
34527 6545
output:
748108997
result:
ok 1 number(s): "748108997"
Test #20:
score: -100
Wrong Answer
time: 0ms
memory: 5104kb
input:
12345 12
output:
726561415
result:
wrong answer 1st numbers differ - expected: '777496209', found: '726561415'