QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#321616#3295. 循环之美LVJBot1100 ✓432ms40468kbC++141.7kb2024-02-05 00:30:452024-02-05 00:30:46

Judging History

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

  • [2024-02-05 00:30:46]
  • 评测
  • 测评结果:100
  • 用时:432ms
  • 内存:40468kb
  • [2024-02-05 00:30:45]
  • 提交

answer

// LVJ submission #65bfbbafce3cbd022bb81820@1707064240656
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>

typedef long long LL;
const int MK = 2005;
const int S = 31622;
const int MN23 = 1000005;
const int MP = 78505;
const int MD = 25;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

bool ip[MN23];
int p[MP], pc;
int mu[MN23], Smu[MN23];

inline void Init(int N) {
	mu[1] = 1;
	for (int i = 2; i <= N; ++i) {
		if (!ip[i]) p[++pc] = i, mu[i] = -1;
		for (int j = 1; j <= pc && p[j] * i <= N; ++j) {
			ip[p[j] * i] = 1;
			if (i % p[j]) mu[p[j] * i] = -mu[i];
			else break;
		}
	}
	for (int i = 1; i <= N; ++i) Smu[i] = Smu[i - 1] + mu[i];
}

int N, M, K, N23;
int A[MK], Vl[MD], cd;

std::map<int, LL> mp[MD];

LL Sum(int N, int K) {
	if (!N) return 0;
	if (K == 1 && N <= N23) return Smu[N];
	if (mp[K].count(N)) return mp[K][N];
	if (K > 1) {
		LL Ans = 0;
		for (int j = 1; j <= K; ++j)
			if (Vl[K] % Vl[j] == 0 && mu[Vl[j]])
				Ans += Sum(N / Vl[j], j);
		return mp[K][N] = Ans;
	}
	LL Ans = 1;
	for (int i = 2, j; i <= N; i = j + 1) {
		j = N / (N / i);
		Ans -= (j - i + 1) * Sum(N / i, 1);
	}
	return mp[1][N] = Ans;
}

LL Ans;

int main() {
	scanf("%d%d%d", &N, &M, &K);
	for (int i = 1; i <= K; ++i) A[i] = A[i - 1] + (gcd(i, K) == 1);
	Init(N23 = std::max((int)pow(N, 2./3), K));
	for (int i = 1; i <= K; ++i) if (K % i == 0 && (mu[i] || i == K)) Vl[++cd] = i;
	for (int i = 1, kN, kM, j; i <= N && i <= M; i = j + 1) {
		kN = N / i, kM = M / i;
		j = std::min(N / kN, M / kM);
		Ans = Ans + kN * ((LL)kM / K * A[K] + A[kM % K]) * (Sum(j, cd) - Sum(i - 1, cd));
	}
	printf("%lld\n", Ans);
	return 0;
}

详细

Test #1:

score: 4
Accepted
time: 1ms
memory: 5996kb

input:

9 19 2

output:

78

result:

ok 1 number(s): "78"

Test #2:

score: 4
Accepted
time: 0ms
memory: 6084kb

input:

97 9998 2

output:

395230

result:

ok 1 number(s): "395230"

Test #3:

score: 4
Accepted
time: 0ms
memory: 6140kb

input:

925 776383828 2

output:

291158369963

result:

ok 1 number(s): "291158369963"

Test #4:

score: 4
Accepted
time: 13ms
memory: 7220kb

input:

8901 326326877 2

output:

1177246855340

result:

ok 1 number(s): "1177246855340"

Test #5:

score: 4
Accepted
time: 1ms
memory: 6080kb

input:

10 18 3

output:

85

result:

ok 1 number(s): "85"

Test #6:

score: 4
Accepted
time: 1ms
memory: 6016kb

input:

99 9124 3

output:

414445

result:

ok 1 number(s): "414445"

Test #7:

score: 4
Accepted
time: 1ms
memory: 6192kb

input:

876 435006787 3

output:

173773888677

result:

ok 1 number(s): "173773888677"

Test #8:

score: 4
Accepted
time: 18ms
memory: 7092kb

input:

9077 999901423 3

output:

4138517057280

result:

ok 1 number(s): "4138517057280"

Test #9:

score: 4
Accepted
time: 1ms
memory: 6144kb

input:

8 18 70

output:

44

result:

ok 1 number(s): "44"

Test #10:

score: 4
Accepted
time: 1ms
memory: 6008kb

input:

99 7689 100

output:

257777

result:

ok 1 number(s): "257777"

Test #11:

score: 4
Accepted
time: 1ms
memory: 6312kb

input:

904 791040170 780

output:

168263165839

result:

ok 1 number(s): "168263165839"

Test #12:

score: 4
Accepted
time: 14ms
memory: 7688kb

input:

9752 700341570 1900

output:

2191452433400

result:

ok 1 number(s): "2191452433400"

Test #13:

score: 4
Accepted
time: 52ms
memory: 9452kb

input:

67890 96085338 98

output:

2313308017745

result:

ok 1 number(s): "2313308017745"

Test #14:

score: 4
Accepted
time: 269ms
memory: 17984kb

input:

199752 831377991 582

output:

49964059187765

result:

ok 1 number(s): "49964059187765"

Test #15:

score: 4
Accepted
time: 144ms
memory: 15344kb

input:

402829 239198013 1974

output:

25093728301882

result:

ok 1 number(s): "25093728301882"

Test #16:

score: 4
Accepted
time: 65ms
memory: 11332kb

input:

920812 97518123 30

output:

22745569858620

result:

ok 1 number(s): "22745569858620"

Test #17:

score: 4
Accepted
time: 432ms
memory: 28536kb

input:

2000000 902323111 630

output:

399982029285532

result:

ok 1 number(s): "399982029285532"

Test #18:

score: 4
Accepted
time: 349ms
memory: 25272kb

input:

5000000 1000000000 1122

output:

1315768281328847

result:

ok 1 number(s): "1315768281328847"

Test #19:

score: 4
Accepted
time: 29ms
memory: 11608kb

input:

10000000 100000000 100

output:

337737297053529

result:

ok 1 number(s): "337737297053529"

Test #20:

score: 4
Accepted
time: 313ms
memory: 27008kb

input:

19283746 992837465 330

output:

4445506723817465

result:

ok 1 number(s): "4445506723817465"

Test #21:

score: 4
Accepted
time: 267ms
memory: 24816kb

input:

20000000 1000000000 1540

output:

5417869022476158

result:

ok 1 number(s): "5417869022476158"

Test #22:

score: 4
Accepted
time: 70ms
memory: 14816kb

input:

79331983 76782798 210

output:

1350083306292618

result:

ok 1 number(s): "1350083306292618"

Test #23:

score: 4
Accepted
time: 24ms
memory: 10768kb

input:

99997327 86263723 1999

output:

5241443368179591

result:

ok 1 number(s): "5241443368179591"

Test #24:

score: 4
Accepted
time: 363ms
memory: 40468kb

input:

967272686 923726686 1260

output:

198034442762888587

result:

ok 1 number(s): "198034442762888587"

Test #25:

score: 4
Accepted
time: 312ms
memory: 38736kb

input:

999193233 997313141 1848

output:

242952866318443894

result:

ok 1 number(s): "242952866318443894"

Extra Test:

score: 0
Extra Test Passed