luogu#P7571. 「MCOI-05」幂积

「MCOI-05」幂积

Background

Bookworm has 101010^{10} gold medals.

Bookworm is organizing his nn gold medals. His medals have four types, in order: NOI gold medal, IOI gold medal, IMO gold medal, ICPC WF gold medal. On day 11 to day nn, he ACs a contest each day and gets one gold medal of one of the types above. For a given parameter kk, the value of the gold medal obtained on day ii is 11 if k=0k=0, and ii if k=1k=1.

Every day, Bookworm uses some magical method to choose which contest to AC that day. For day ii, let i=p1×p2×pki=p_1\times p_2\times\dots p_k, where p1,p2,,pkp_1,p_2,\dots,p_k are all primes. Bookworm computes xx, where xx is the remainder of p1+p2++pkp_1+p_2+\dots+p_k modulo 44, and then ACs the (x+1)(x+1)-th type of contest, obtaining a gold medal of the (x+1)(x+1)-th type.

Bookworm has too many medals, so he invites you to help him compute, among these nn medals, the sum of values in each type. But Bookworm is not satisfied with that. He gives you mm and kk, and asks you to compute the answer for each 1im1\le i\le\lfloor\sqrt m\rfloor when n=min=\lfloor\frac mi\rfloor.

Problem Description

Define the function f(piai)=aipif(\prod p_i^{a_i})=\sum a_ip_i, where pip_i are primes. In particular, f(1)=0f(1)=0.

For k{0,1}k\in\{0,1\}, define the function gg as:

g(n,k,r)=i=1nik[f(i)r(mod4)]g(n,k,r)=\sum_{i=1}^ni^k[f(i)\equiv r\pmod 4]

Given mm and kk, for all 1im1\le i\le\lfloor\sqrt m\rfloor, compute g(mi,k,r)g(\lfloor\frac mi\rfloor,k,r) for all 0r<40\le r<4.

Input Format

The first line contains a positive integer mm.
The second line contains a non-negative integer kk.

Output Format

Output m\lfloor\sqrt m\rfloor lines.
The ii-th line contains four non-negative integers, and the rr-th non-negative integer is g(mi,k,r)g(\lfloor\frac mi\rfloor,k,r).

10 0
2 2 3 3
2 1 1 1
1 0 1 1

Hint

Explanation of Sample 1

f=[0,2,3,0,1,1,3,2,2,3,]f=[0,2,3,0,1,1,3,2,2,3,\dots]

Constraints

This problem uses bundled testdata.

Subtask Score mm kk
1 5 pts 107\le 10^7 None
2 15 pts 109\le10^9 =0=0
3 25 pts None
4 109\le10^9 None
5 30 pts None

For 100%100\% of the testdata, 1m10101\le m\le10^{10} and 0k10\le k\le1.

Translated by ChatGPT 5