The way to solve this problem is easy. Just let $$$n=p_1^{c_1}p_2^{c_2}\cdots p_k^{c_k}$$$ ($$$p_i$$$ are pairwise different) then the answer will be

There're more than one way to get ans (a simple way is to use prefix product). But today I read a solution which I could not understand:

**solution**

My only question: why we can keep the factor 2 by `mod 2*(mod-1)`

? Thanks in advance

It's actually a quite fancy trick IMO. I tried to explain as detailed as I can:

Let $$$x$$$ denote $$$\prod{(c_j + 1)}$$$. We know that $$$A = c_i \cdot x$$$ is always even since both $$$c_i$$$ and $$$c_i + 1$$$ are present in that product (exactly one is even). So, $$$\frac{A}{2}$$$ is an integer.

(We already knew it because it must be even somehow but I wanted to clarify this part also.)Let's denote $$$p-1$$$ by $$$m$$$ for convenience. We want to find the remainder of $$$\frac{A}{2}$$$ divided by $$$m$$$, that is, the non-negative integer $$$r < m$$$ such that $$$\frac{A}{2} = km + r$$$ where $$$k$$$ is an integer.

We can multiply both sides by $$$2$$$ to obtain $$$A = k \cdot 2m + 2r$$$. So, if we can obtain a number congruent to $$$A \bmod 2m$$$, it is going to be even (as both $$$A$$$ and $$$2m$$$ are even).

Notice that $$$A' = c_i \cdot (x \ \% \ 2m)$$$ is congruent to $$$A \bmod 2m$$$, so, $$$A'$$$ can also be written as $$$A' = k' \cdot 2m + 2r$$$, which indicates that $$$\frac{A'}{2} = k'm + r$$$. As a result, it is safe to divide $$$A'$$$ by $$$2$$$ and then take $$$\frac{A'}{2}\bmod m$$$.