QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#197935#3853. Lines in a gridForever_Young#WA 146ms162688kbC++141.7kb2023-10-02 22:11:362023-10-02 22:11:38

Judging History

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

  • [2023-10-02 22:11:38]
  • 评测
  • 测评结果:WA
  • 用时:146ms
  • 内存:162688kb
  • [2023-10-02 22:11:36]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long double D;
typedef pair<int, int> pii;
typedef long long LL;
const int inf = 1e9 + 7;
const int mod = 1000003;
const int N = 10000011;
const int L = 10000000;
int np = 0;
int primes[N], f[N], mu[N], smu[N], mnp[N];
LL calc(int n) {
	return (1ll + n) * n / 2 % mod * (((1ll + n) * n / 2) % mod) % mod;
}
int solve(int n) {
	if(n == 0) return 0;
	int res = 0;
	int i = 1;
	for(;;) {
		
		int div = n / i;
		int nxt = n / div + 1;
		//cout << n << ' ' << i << ' ' << nxt << endl;
		res = (res + calc(div) * (smu[nxt - 1] - smu[i - 1] + mod) % mod) % mod;
		//cout << calc(div) << ' ' << (smu[nxt - 1] - smu[i - 1]) << endl;
		i = nxt;
		if(i > n) break;
	}
	//cout << "s" << n << ' ' << res << endl;
	return res;
}
int main() {
	mu[1] = 1;
	primes[0] = inf;
	fill(f + 2, f + L + 1, true);
	for(int i = 2; i <= L; i++) {
		if(f[i]) {
			primes[++np] = i;
			mnp[i] = np;
			mu[i] = -1;
		}
		for(int j = 1; j <= np && primes[j] * i <= L && i % primes[j - 1]; j++) {
			f[primes[j] * i] = false;
			mnp[primes[j] * i] = j;
			if(mnp[primes[j] * i] == mnp[i]) {
				mu[primes[j] * i] = 0;
			}else {
				mu[primes[j] * i] = -1 * mu[i];
			}
		}
	}
	for(int i = 1; i <= L; i++) {
		//if(i <= 10) printf("%d %d %d\n", i, mu[i], smu[i]);
		smu[i] = (smu[i - 1] + mu[i] + mod) % mod;
	}
	//cout << "!" << endl;
	int Q;
	scanf("%d", &Q);
	for(int i = 1; i <= Q; i++) {
		int n;
		scanf("%d", &n);
		n--;
		int ans = (solve(n) - solve(n / 2) + mod) % mod;
		//cout << "a" << ans << endl;
		ans = ans * 2 % mod;
		ans = (ans + 2 + n * 2) % mod;
		if(n == 0) ans = 0;
		printf("%d\n", ans);
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 146ms
memory: 162688kb

input:

10
1 2 3 4 5 6 7 8 9 10

output:

0
6
20
74
174
424
738
1424
2210
3616

result:

wrong answer 4th lines differ - expected: '62', found: '74'