QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#301412#3681. 模积和duongnc0000 99ms3624kbC++233.3kb2024-01-09 20:18:112024-01-09 20:18:12

Judging History

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

  • [2024-01-09 20:18:12]
  • 评测
  • 测评结果:0
  • 用时:99ms
  • 内存:3624kb
  • [2024-01-09 20:18:11]
  • 提交

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() {
	nquo = n / (nr + 1);
	if (nquo == 0) {
		nl = nr + 1;
		nr = max(nl, min(n, m));
	}
	else {
		nl = nr + 1;
		int cl = nl, cr = min(n, m);
		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() {
	mquo = m / (mr + 1);
	if (mquo == 0) {
		ml = mr + 1;
		mr = max(ml, min(n, m));
	}
	else {
		ml = mr + 1;
		int cl = ml, cr = min(n, m);
		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();
	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();
	}

	ml = mr = 0;
	get_next_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();
	}

	// cout << resn << " " << resm << endl;
	res += (resn % mod) * (resm % mod) % mod;

	nl = nr = ml = mr = 0;
	get_next_n(); get_next_m();
	while (nr <= min(n, m) and mr <= min(n, m)) {
		int L = max(nl, nr);
		int R = min(ml, 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 << " " << ml << " " << mr << 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: 0
Time Limit Exceeded

input:

195 631


output:


result:


Test #2:

score: 0
Wrong Answer
time: 99ms
memory: 3624kb

input:

64 10872681


output:

7131829

result:

wrong answer 1st lines differ - expected: '1651075', found: '7131829'

Test #3:

score: 0
Time Limit Exceeded

input:

75 135111825


output:


result:


Test #4:

score: 0
Time Limit Exceeded

input:

63 116177601


output:


result:


Test #5:

score: 0
Time Limit Exceeded

input:

405041 602225


output:


result:


Test #6:

score: 0
Time Limit Exceeded

input:

727429 937589


output:


result:


Test #7:

score: 0
Time Limit Exceeded

input:

70337281 243937321


output:


result:


Test #8:

score: 0
Time Limit Exceeded

input:

136349929 257383657


output:


result:


Test #9:

score: 0
Time Limit Exceeded

input:

539154474 305587405


output:


result:


Test #10:

score: 0
Time Limit Exceeded

input:

719865785 277727262


output:


result: