QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#301417 | #3681. 模积和 | duongnc000 | 100 ✓ | 11ms | 3620kb | C++23 | 3.4kb | 2024-01-09 20:29:11 | 2024-01-09 20:29:11 |
Judging History
answer
/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt")
*/
#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define i64 long long
#define pb push_back
#define ff first
#define ss second
#define isz(x) (int)x.size()
using namespace std;
const int mxN = 2e5 + 5;
const int mod = 19940417;
const i64 oo = 1e18;
const int inv2 = 9970209;
const int inv6 = 3323403;
int calc1(int l, int r) {
return 1ll * (l + r) * (r - l + 1) % mod * inv2 % mod;
}
int pfx2(int n) {
return 1ll * n * (n + 1) % mod * (2 * n + 1) % mod * inv6 % mod;
}
int calc2(int l, int r) {
return (pfx2(r) - pfx2(l - 1) + mod) % mod;
}
int n, m;
int nl, nr, nquo;
int ml, mr, mquo;
i64 res, resn, resm;
void get_next_n(int lim = min(n, m)) {
// assert(nquo != n / (nr + 1));
nquo = n / (nr + 1);
if (nquo == 0) {
nl = nr + 1;
nr = max(nl, lim);
}
else {
nl = nr + 1;
int cl = nl, cr = lim;
while (cl < cr) {
int mid = (cl + cr + 1) >> 1;
if (n / mid >= nquo) cl = mid;
else cr = mid - 1;
}
nr = cl;
}
}
void get_next_m(int lim = min(n, m)) {
// assert(m / (mr + 1) != mquo);
mquo = m / (mr + 1);
if (mquo == 0) {
ml = mr + 1;
mr = max(ml, lim);
}
else {
ml = mr + 1;
int cl = ml, cr = lim;
while (cl < cr) {
int mid = (cl + cr + 1) >> 1;
if (m / mid >= mquo) cl = mid;
else cr = mid - 1;
}
mr = cl;
}
}
void solve() {
cin >> n >> m;
nl = nr = 0;
get_next_n(n);
while (nr <= n) {
i64 ans = 0;
ans += 1ll * n * (nr - nl + 1) % mod;
ans -= 1ll * nquo * calc1(nl, nr) % mod;
ans = (ans % mod + mod) % mod;
resn += ans;
get_next_n(n);
}
ml = mr = 0;
get_next_m(m);
while (mr <= m) {
i64 ans = 0;
ans += 1ll * m * (mr - ml + 1) % mod;
ans -= 1ll * mquo * calc1(ml, mr) % mod;
ans = (ans % mod + mod) % mod;
resm += ans;
get_next_m(m);
}
// cout << resn << " " << resm << endl;
res += (resn % mod) * (resm % mod) % mod;
nl = nr = ml = mr = 0;
get_next_n(); get_next_m();
while (nl <= nr and nr <= min(n, m) and ml <= mr and mr <= min(n, m)) {
int L = max(nl, ml);
int R = min(nr, mr);
i64 ans = 0;
ans += 1ll * n * m % mod * (R - L + 1) % mod;
ans -= 1ll * nquo * m % mod * calc1(L, R) % mod;
ans -= 1ll * mquo * n % mod * calc1(L, R) % mod;
ans += 1ll * nquo * mquo % mod * calc2(L, R) % mod;
ans = (ans % mod + mod) % mod;
res -= ans;
if (nr == R) get_next_n();
if (mr == R) get_next_m();
// cout << nl << " " << nr << " " << nquo << " " << ml << " " << mr << " " << mquo << endl;
}
cout << (res % mod + mod) % mod << endl;
}
signed main() {
#ifndef CDuongg
if(fopen(taskname".inp", "r"))
assert(freopen(taskname".inp", "r", stdin)), assert(freopen(taskname".out", "w", stdout));
#else
freopen("bai3.inp", "r", stdin);
freopen("bai3.out", "w", stdout);
auto start = chrono::high_resolution_clock::now();
#endif
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1; //cin >> t;
while(t--) solve();
#ifdef CDuongg
auto end = chrono::high_resolution_clock::now();
cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '=';
cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
cout << "Check array size pls sir" << endl;
#endif
}
详细
Test #1:
score: 10
Accepted
time: 1ms
memory: 3460kb
input:
195 631
output:
13499636
result:
ok single line: '13499636'
Test #2:
score: 10
Accepted
time: 1ms
memory: 3452kb
input:
64 10872681
output:
1651075
result:
ok single line: '1651075'
Test #3:
score: 10
Accepted
time: 2ms
memory: 3452kb
input:
75 135111825
output:
1099449
result:
ok single line: '1099449'
Test #4:
score: 10
Accepted
time: 2ms
memory: 3448kb
input:
63 116177601
output:
17215072
result:
ok single line: '17215072'
Test #5:
score: 10
Accepted
time: 1ms
memory: 3620kb
input:
405041 602225
output:
4906861
result:
ok single line: '4906861'
Test #6:
score: 10
Accepted
time: 1ms
memory: 3448kb
input:
727429 937589
output:
4099574
result:
ok single line: '4099574'
Test #7:
score: 10
Accepted
time: 6ms
memory: 3396kb
input:
70337281 243937321
output:
16331489
result:
ok single line: '16331489'
Test #8:
score: 10
Accepted
time: 7ms
memory: 3464kb
input:
136349929 257383657
output:
19504124
result:
ok single line: '19504124'
Test #9:
score: 10
Accepted
time: 10ms
memory: 3448kb
input:
539154474 305587405
output:
8781805
result:
ok single line: '8781805'
Test #10:
score: 10
Accepted
time: 11ms
memory: 3448kb
input:
719865785 277727262
output:
937958
result:
ok single line: '937958'