QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#291158#2586. 旧试题MoRanSky100 ✓2366ms43388kbC++232.8kb2023-12-26 05:07:542023-12-26 05:07:56

Judging History

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

  • [2023-12-26 05:07:56]
  • 评测
  • 测评结果:100
  • 用时:2366ms
  • 内存:43388kb
  • [2023-12-26 05:07:54]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <unordered_map>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;

typedef long long LL;

const int S = 1e5 + 1, T = 1e5 + 1, INF = 0x3f3f3f3f, P = 1e9 + 7;

int primes[S], tot, fac[S], mu[S], h[S], d[8], top[8], A[8][S * 20], B[8][S * 20];

bool st[S], vis[S];

int F[8][T], G[8][T];

vector<int> e[S];

int s[S], ans;
int a, b, c; 

int f(int n, int k) {
	if (n == 0) return 0;
	if (n == 1) return 1;
	if (k == 0) return mu[n];
	if (F[k][n] != -1) return F[k][n];
	else {
	    ++top[k];
		A[k][top[k]] = k, B[k][top[k]] = n;
		int p = fac[d[k]];
		return F[k][n] = (f(n, k - 1) + f(n / p, k)) % P;
	} 
}

void init() {
	for (int i = 1; i < S; i++) mu[i] = 1;
	for (int i = 2; i < S; i++) {
		if (!st[i]) primes[++tot] = i, mu[i] = -1, fac[i] = i;
		for (int j = 1; primes[j] * i < S; j++) {
			st[primes[j] * i] = true;
			fac[primes[j] * i] = primes[j];
			if (i % primes[j] == 0) {
				mu[i * primes[j]] = 0;
				break;
			}
			mu[i * primes[j]] = -mu[i];
		}
	}
	
	for (int i = 2; i < S; i++) (mu[i] += mu[i - 1] + P) %= P;
}


int g(int n, int k) {
	if (n == 0) return 0;
	if (G[k][n] != -1) return G[k][n];
	else if (k > 0) {
	    ++top[k];
		A[k][top[k]] = k, B[k][top[k]] = n;
		int p = fac[d[k]];
		return G[k][n] = ((LL)g(n, k - 1) - g(n / p, k - 1) + P) % P;
	} else {
		++top[k];
		A[k][top[k]] = k, B[k][top[k]] = n;
		int res = 0;
		for (int l = 1, r, t; l <= n; l = r + 1) {
			t = n / l, r = n / t;
			res = (res + t * (r - l + 1ll)) % P;
		}
		return G[k][n] = res;
	}
}

void dfs(int u, int dep) {
	top[dep] = 0; int s = 0;
	d[dep] = u;
	for (int l = 1, r, t, v; l <= min(b, c); l = r + 1) {
		t = b / l, v = c / l, r = min(min(b, c), min(b / t, c / v));
		s = (s + ((LL)f(r, dep) - f(l - 1, dep) + P) * g(t, dep) % P * g(v, dep)) % P;
	}
	
	h[u] = s;
	for (int i = 0; i < e[u].size(); i++) {
		int v = e[u][i];
		dfs(v, dep + 1);
	}
	
	for (int j = 1; j <= top[dep]; j++) 
		F[A[dep][j]][B[dep][j]] = -1, G[A[dep][j]][B[dep][j]] = -1;
}

int main() {
	memset(F, -1, sizeof F);
	memset(G, -1, sizeof G);
	init();
	int T; scanf("%d", &T);
	while (T--) {
		scanf("%d%d%d", &a, &b, &c);
		for (int i = 1; i <= a; i++) vis[i] = false, e[i].clear();
		ans = 0;
		
		for (int i = 1; i <= a; i++) {
			int s = 0; int x = i;
			for (int j = 2; j * j <= x; j++)
		 		while (x % j == 0 && (x / j) % j == 0) x /= j;
			if (!vis[x] && fac[x] > 1) vis[x] = true,  e[x / fac[x]].push_back(x);
			
		}
		
		dfs(1, 0);
		
		for (int i = 1; i <= a; i++) {
			int s = 0; int x = i;
			for (int j = 2; j * j <= x; j++)
		 		while (x % j == 0 && (x / j) % j == 0) x /= j;
		 	ans = (ans + (LL)h[x] * (a / i)) % P;
		}
		
		printf("%d\n", ans);
	}
}

详细

Test #1:

score: 10
Accepted
time: 51ms
memory: 38420kb

input:

10
2619 2775 2558
2941 2738 2253
2523 2234 2814
2095 2001 2450
2074 2843 2478
2853 2891 2781
2096 2322 2484
2844 2285 2224
2019 2059 2676
2141 2850 2817

output:

427265215
845145293
265815811
249115533
183034505
150848053
247869267
904260863
862484831
861301172

result:

ok 10 lines

Test #2:

score: 10
Accepted
time: 80ms
memory: 38464kb

input:

10
3165 3578 3911
3592 3274 3353
3376 3782 3089
3709 3770 3246
3089 3897 3031
3103 3125 3574
3250 3833 3284
3488 3815 3324
3946 3982 3416
3577 3398 3718

output:

919081513
748091520
336370368
816414205
837085228
14931324
680497479
647476532
166908806
718496336

result:

ok 10 lines

Test #3:

score: 10
Accepted
time: 121ms
memory: 38268kb

input:

10
4519 4189 4072
4052 4002 4157
4230 4435 4363
4515 4028 4451
4399 4551 4688
4456 4358 4471
4109 4537 4572
4323 4752 4528
4361 4905 4348
4117 4434 4810

output:

420450298
615154420
32903889
958731225
922332838
39742175
66516020
632249329
424172857
465363232

result:

ok 10 lines

Test #4:

score: 10
Accepted
time: 844ms
memory: 38792kb

input:

10
17136 18154 18724
16629 12214 17413
15253 10155 13458
17096 13806 16769
15236 14354 18323
13094 19136 16852
17418 18188 17566
16275 10700 19227
18810 19912 11416
15327 12117 17119

output:

726077079
734135143
601896068
393530194
22020991
987568247
831587252
858154598
46655946
526713034

result:

ok 10 lines

Test #5:

score: 10
Accepted
time: 1275ms
memory: 36380kb

input:

7
27755 28517 28482
28438 26289 28481
25044 27828 27248
25434 26802 26393
28156 25264 25282
25245 27052 27762
26292 27348 25746

output:

526394310
849807853
840092589
913471641
273455164
891473827
28209814

result:

ok 7 lines

Test #6:

score: 10
Accepted
time: 1497ms
memory: 43176kb

input:

5
34705 34903 39485
36395 35236 38154
35777 38513 36847
37788 34468 35376
39645 39238 37169

output:

169462122
448448054
986623041
273945179
361303347

result:

ok 5 lines

Test #7:

score: 10
Accepted
time: 1628ms
memory: 43144kb

input:

4
42495 48356 47796
45845 49516 42444
48928 42926 47681
44787 41256 49432

output:

912914940
421832759
944309862
324478867

result:

ok 4 lines

Test #8:

score: 10
Accepted
time: 2313ms
memory: 43388kb

input:

2
83235 96187 90028
95824 85017 96145

output:

91596405
822433137

result:

ok 2 lines

Test #9:

score: 10
Accepted
time: 2366ms
memory: 43288kb

input:

2
85017 81194 93250
99216 90392 97201

output:

694934048
780451544

result:

ok 2 lines

Test #10:

score: 10
Accepted
time: 2064ms
memory: 43120kb

input:

2
100000 100000 99999
100000 99999 99999

output:

936290692
763871123

result:

ok 2 lines