#P11169. 「CMOI R1」Bismuth / Linear Sieve

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

「CMOI R1」Bismuth / Linear Sieve

题目背景

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?……

题目描述

给定以下程序中的 nn(即输入),求以下伪代码的输出结果。

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

请注意此代码不是线性筛,差别在注释过的那一行。

输入格式

一行一个整数,即输入,也就是给定的 nn

输出格式

一行两个非负整数,即伪代码输出。

100
50 30
9876543
4938272 3092277
998877665544332211
499438832772166106 312742219398875473

提示

本题采用捆绑测试,并且存在子任务依赖(只有你拿到了一个子任务前一个子任务的分,你才有可能拿到该子任务的分)。

数据范围

Subtask\text{Subtask} 约束条件 分值
11 n107n\leq 10^7 1010
22 n109n\leq 10^9 4040
33 n1018n\leq 10^{18} 5050

对于 100%100\% 的数据,满足 1n10181\leq n\leq 10^{18}