【51Nod 1769】Clarke and math2

【51Nod 1769】Clarke and math2

Face questions

51Nod

answer

For a number theoretic function \ (F \) , \ (\ sum_ {D |} n-F (D) = (F \ Times. 1) (n-) \) .

In fact, the subject is required \ (G = F \ Times. 1 ^ K \) .

Consider \ (1 ^ k (n) \) how to find, because \ (1 (n) \) is a multiplicative function, so \ (1 ^ k (n) \) is also a multiplicative function.

We consider for \ (n-\) each quality factor \ (P \) and the number of times it \ (R & lt \) , to obtain the corresponding value of the function.

Then each different equivalent \ (i_ {j-1} \) and \ (i_j \) inserting a quality factor expressed by the \ (P \) times, can also be inserted in the same location.

So based on the answers of permutations and combinations, this problem is \ (k-1 + r \ the Choose r \) , then the contribution of each quality factor multiplied together is the answer.

Code

#include <iostream> 
#include <cstdio> 
#include <cstdlib> 
#include <cstring> 
#include <cmath> 
#include <algorithm> 
using namespace std; 
const int Mod = 1e9 + 7; 
inline int gi() { 
    register int data = 0, w = 1; 
    register char ch = 0; 
    while (!isdigit(ch) && ch != '-') ch = getchar(); 
    if (ch == '-') w = -1, ch = getchar(); 
    while (isdigit(ch)) data = (10ll * data + ch - '0') % Mod, ch = getchar(); 
    return w == 1 ? data : (-data + Mod) % Mod; 
} 
int fpow(int x, int y) { 
    int res = 1; 
    while (y) { 
        if (y & 1) res = 1ll * res * x % Mod; 
        x = 1ll * x * x % Mod; 
        y >>= 1; 
    } 
    return res; 
} 
const int MAX_N = 5e5 + 5; 
int fac[25], ifc[25], C[25]; 
int N, K, f[MAX_N], g[MAX_N], h[MAX_N], cur[MAX_N]; 

int main () { 
#ifndef ONLINE_JUDGE 
    freopen("cpp.in", "r", stdin); 
#endif 
    fac[0] = 1; for (int i = 1; i <= 20; i++) fac[i] = 1ll * i * fac[i - 1] % Mod; 
    ifc[20] = fpow(fac[20], Mod - 2); 
    for (int i = 19; ~i; i--) ifc[i] = 1ll * ifc[i + 1] * (i + 1) % Mod; 
    N = gi(), K = gi(); 
    for (int i = 1; i <= N; i++) f[i] = gi(), g[i] = 1, cur[i] = i; 
    for (int i = 0; i <= 20; i++) { 
        int nw = (i + K - 1) % Mod; C[i] = ifc[i]; 
        for (int j = 0; j < i; j++) C[i] = 1ll * C[i] * (nw - j + Mod) % Mod; 
    } 
    for (int i = 2; i <= N; i++) { 
        if (cur[i] == 1) continue; 
        for (int j = i; j <= N; j += i) { 
            int k = 0; 
            while (cur[j] % i == 0) ++k, cur[j] /= i; 
            g[j] = 1ll * g[j] * C[k] % Mod; 
        } 
    } 
    for (int i = 1; i <= N; i++) 
        for (int j = i; j <= N; j += i) 
            h[j] = (h[j] + 1ll * f[i] * g[j / i]) % Mod; 
    for (int i = 1; i <= N; i++) printf("%d ", h[i]); 
    putchar('\n'); 
    return 0; 
}

Guess you like

Origin www.cnblogs.com/heyujun/p/11792129.html