QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#166891#4278. GCD vs LCMjeffqiWA 2ms4284kbC++141.9kb2023-09-06 20:11:552023-09-06 20:11:56

Judging History

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

  • [2023-09-06 20:11:56]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4284kb
  • [2023-09-06 20:11:55]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define eb emplace_back
#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(v) ((int)v.size())
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define ull unsigned ll
#define i128 __int128
using namespace std;

namespace qiqi {
	const int P = 1e9+7,N = 1e5;
	vll sum;
	void init(int n = N) {
		vi p,mu(n+1,P); mu[1] = 1;
		for (int i = 2; i <= n; i++) {
			if (mu[i] == P) {
				mu[i] = -1; p.eb(i);
			}
			for (auto x:p) {
				if (i*x > n) {
					break;
				}
				if (!(i%x)) {
					mu[i*x] = 0;
					break;
				}
				mu[i*x] = mu[i]*mu[x];
			}
		}
		sum.assign(n+1,0);
		for (int i = 1; i <= n; i++) {
			sum[i] = (sum[i-1]+1ll*i*i*mu[i])%P;
		}
	}
	void main() {
		int n,m,lim;
		cin >> n >> m >> lim;
		lim = min({lim,n,m});
		ll ans = 0;
		auto s = [&](ll l,ll r) {
			return (l+r)*(r-l+1)/2%P;
		};
		auto calc = [&](int n,int m) {
			ll res = 0;
			if (n > m) {
				swap(n,m);
			}
			for (int l = 1,r; l <= n; l = r+1) {
				r = min(n/(n/l),m/(m/l));
				res = (res+(sum[r]-sum[l-1])*s(1,n/l)%P*s(1,m/l))%P;
			}
			return res;
		};
		for (int l = 1,r; l <= lim; l = r+1) {
			r = min({lim,n/(n/l),m/(m/l)});
			ans = (ans+s(l,r)*calc(n/l,m/l))%P;
		}
		ans = (ans+P)%P;
		string str;
		while (ans) {
			str += ans%10+'0';
			ans /= 10;
		}
		cout << str << '\n';
	}
}

int main() {
//	clock_t st = clock();
//	freopen("test.in","r",stdin);
//	freopen("test.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	qiqi::init();

	int T = 1;
	cin >> T;
	while (T--) {
		qiqi::main();
	}

//	cout << (double)(clock()-st)/CLOCKS_PER_SEC << '\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 4284kb

input:

2
2 2 1
3 4 2

output:

5
54

result:

wrong answer 2nd numbers differ - expected: '45', found: '54'