luogu#P8104. 「LCOI2022」 Cow Function

    ID: 7249 远端评测题 500~4000ms 256MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2022数论O2优化素数判断,质数,筛法

「LCOI2022」 Cow Function

Background

Bessie and the others are sitting in the newly merged barn, studying loop unrolling with Farmer John.

Farmer John says that if the unrolling step size is 88, it can greatly improve program efficiency.

After class, Farmer John assigned a problem: compute f(x)=i=1x3ω(i)f(x)=\sum\limits_{i=1}^x3^{\omega(i)} within 11 second. Bessie wrote a Θ(nlog2nn)Θ(n\log_2 n\sqrt n) program in 2020 minutes, but it got TLE right after submission. So Bessie came to you for help.

Problem Description

She wants to compute, for k{0,1,,7}k\in\{0,1,\dots,7\}, the value of $f(n)=\sum_{i=1}\limits^n[\omega(i)\equiv k\pmod 8]3^{\omega(i)}$.

In the formula above, ω(i)\omega(i) denotes how many distinct prime factors ii has. For example, ω(12)=ω(6)=2,ω(114514)=3\omega(12)=\omega(6)=2,\omega(114514)=3.

Input Format

A single line containing an integer nn.

Output Format

Output 88 lines. The kk-th line (for k=0,1,2,3,4,5,6,7k=0,1,2,3,4,5,6,7) should output the value of $f(n)=\sum_{i=1}\limits^n[\omega(i)\equiv k \pmod 8]3^{\omega(i)}$.

30
1
48
108
27
0
0
0
0
114514
1
32826
344727
1199826
1504818
538731
25515
0

Hint

Constraints

subtask nn\le points time limit
11 100100 1010 500ms500\texttt{ms}
22 2×1062\times10^6 2020 1000ms1000\texttt{ms}
33 3×1073\times10^7
44 10910^9 4000ms4000\texttt{ms}
55 101010^{10} 3030

If you need a loop unrolling generator, please download it from the attachment.

Translated by ChatGPT 5