#P7571. Prime Exponent Weighted Sum Function
Prime Exponent Weighted Sum Function
Prime Exponent Weighted Sum Function
Given the function \( f(\prod p_i^{a_i}) = \sum a_i p_i \) defined for any positive integer (with \( f(1)=0 \)), where \( p_i \) are prime numbers, and for \( k\in\{0,1\} \) define the function \( g \) by:
\[ g(n,k,r)=\sum_{i=1}^{n} i^k \; [f(i)\equiv r\pmod{4}], \quad 0\le r<4, \]
Here \([P]\) is the indicator function which equals 1 if the property \( P \) is true and 0 otherwise.
For a given positive integer \( m \) and integer \( k \) (either 0 or 1), for every integer \( i \) such that \( 1\le i\le \lfloor\sqrt{m}\rfloor \), let \( n = \lfloor m/i \rfloor \). Your task is to compute \( g(n, k, r) \) for all residues \( r=0,1,2,3 \).
Note: When \( k=0 \), the weight \( i^0 \) equals 1 for every \( i \); when \( k=1 \), the weight is \( i \) itself.
inputFormat
The input consists of a single line containing two integers separated by a space:
- \( m \): a positive integer.
- \( k \): an integer which is either 0 or 1.
It is guaranteed that \( m \) is large enough so that at least one line of output is produced.
outputFormat
For each integer \( i \) from 1 to \( \lfloor\sqrt{m}\rfloor \), output one line containing four space‐separated integers. The four integers on the line correspond to \( g(\lfloor m/i \rfloor, k, 0) \), \( g(\lfloor m/i \rfloor, k, 1) \), \( g(\lfloor m/i \rfloor, k, 2) \), and \( g(\lfloor m/i \rfloor, k, 3) \) respectively.
sample
10 0
2 2 3 3
1 1 1 1
1 0 1 1
</p>