#P11169. 「CMOI R1」Bismuth / Linear Sieve

    ID: 9565 远端评测题 500ms 128MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>数学2024洛谷原创Special JudgeO2优化

「CMOI R1」Bismuth / Linear Sieve

Background

Can you imagine find wakeless,like a satellite,in the black sky?

Somewhere,like a star.

We dream about things way beyond this atmosphere.

At we're now,on the air.

……

But I eventually evaporates in a blackhole…

Will I just stick up there?……

Problem Description

Given nn in the following program (i.e., the input), find the output of the following pseudocode.

Input n
For i := 1 to n
	is_not_prime[i] := 0
cntp := 0
counter := 0
For i := 2 to n {
	If is_not_prime[i] = 0 {
		cntp := cntp + 1
		primes[cntp] := i
	}
	For j := 1 to cntp {
		If i * primes[j] > n
			break
		is_not_prime[i * primes[j]] := 1
		If i Mod primes[j] > 0 // should be `If i Mod primes[j] = 0` in Sieve of Euler
			break
		counter := counter + 1
	}
}
Print cntp, counter

Please note that this code is not a linear sieve. The difference is the line marked with a comment.

Input Format

One line with one integer, which is the input, i.e., the given nn.

Output Format

One line with two non-negative integers, which are the output of the pseudocode.

100
50 30
9876543
4938272 3092277
998877665544332211
499438832772166106 312742219398875473

Hint

This problem uses bundled tests, and there are dependent subtasks (only if you get the score of the previous subtask can you possibly get the score of this subtask).

Constraints

Subtask\text{Subtask} Constraints Score
11 n107n\leq 10^7 1010
22 n109n\leq 10^9 4040
33 n1018n\leq 10^{18} 5050

For 100%100\% of the testdata, 1n10181\leq n\leq 10^{18}.

Translated by ChatGPT 5