On a number of people: Mobius inversion, Bernoulli numbers

Found in polynomial time he will not do Bernoulli numbers, he recommended back of solving the problem.

Then I discovered that God really is a big problem, but there are some very important ideas.

After the leakage problem can not lose the knowledge or else be forced to fill the hole it is really uncomfortable.

 

Italian title equation:

$ \sum\limits_{i=1}^{N} \left[ gcd \left( i,N \right) =1 \right] i^d $

Classic inversion:

$=\sum\limits_{i=1}^{N} i^d \sum\limits_{j|i \ and \ j|N} \mu(j)$

$=\sum\limits_{j|N} \sum\limits_{i=1}^{\frac{N}{j}} (ij)^d \mu(j)$

$=\sum\limits_{j|N} \mu(j) j^d \sum\limits_{i=1}^{\frac{N}{j}}i^d$

Followed by natural numbers power and formulas. If you had not heard of Bernoulli numbers, then you can guesswork following conclusions.

If the number of Bernoulli heard, then you know that for certain d, $ \ sum \ limits_ {i = 1} ^ {n} i ^ d = \ sum \ limits_ {i = 1} ^ {d + 1 } a_i \ times n ^ {i} $

Wherein a_i $ $ represents a particular factor does not vary with changes in n. This proved to be correct, I will not prove the theory.

In this case there was obtained a d + 1 degree polynomial in n, the sum of the complexity associated with the related n to d. (Application number Bernoulli)

Bernoulli numbers have the formula: $ \ sum \ limits_ {i = 1} ^ {n} i ^ d = \ frac {1} {d + 1} \ sum \ limits_ {i = 0} ^ {d} C_ {d + 1} ^ {i} B_i n ^ {d + 1-i} $

So as long as we solve a number of Bernoulli you can get all $ a_i $ value above.

But first we did not, followed by data range of this problem is very small, so we can choose to d + 1 x's value into the above polynomial melon silk elimination, you can solve all $ a_i $ value.

Then the natural numbers power and question (if) we have solved. Continue to simplify the original formula:

$=\sum\limits_{j|N} \mu(j) j^d \sum\limits_{i=1}^{d+1}(\frac{N}{j})^i \times a_i$

$=\sum\limits_{i=1}^{d+1} a_i \sum\limits_{j|N} \mu(j) \times j^d \times  (\frac{N}{j})^i$

$=\sum\limits_{i=1}^{d+1} a_i \times N^i \sum\limits_{j|N} \mu(j) \times j^{d-i}$

Observation and behind that type, it is the multiplication of two functions of the product, is still multiplicative function, and the subject has been given of the prime factorisation, which is convenient.

From another meaning, each quality factor is considered in turn, only in the number of prime factors is 0 or 1 contributes to answer the remaining time $ \ mu (j) $ 0's.

Therefore, considering only the values ​​1 and the p-type, and because it is a function of the product, so that the quality factor for each of the multiplication results.

The final form of the equation:

$=\sum\limits_{i=1}^{d+1} a_i \times N^i \prod\limits_{j=1}^{w} (1-p_j^{d-1-i})$

Indeed painful AC. Miku big thanks to the guidance of God.

 1 #include<cstdio>
 2 #define int long long
 3 #define mod 1000000007
 4 int d,w,fac[105],inv[105],N=1,p[1005],t[1005],mx[102][102],ans;
 5 int pow(int b,int t,int a=1){for(;t;t>>=1,b=b*b%mod)if(t&1)a=a*b%mod;return a;}
 6 void Gauss(){
 7     for(int i=1;i<=d+1;++i){
 8         int x=pow(mx[i][i],mod-2);
 9         for(int j=i;j<=d+2;++j)mx[i][j]=mx[i][j]*x%mod;
10         for(int j=i+1;j<=d+1;++j)for(int k=d+2;k>=i;--k)mx[j][k]=(mx[j][k]-mx[i][k]*mx[j][i]%mod+mod)%mod;
11     }
12     for(int i=d+1;i;--i)for(int j=i-1;j;--j)mx[j][d+2]=(mx[j][d+2]-mx[j][i]*mx[i][d+2]%mod+mod)%mod;
13 }
14 signed main(){
15     scanf("%lld%lld",&d,&w);fac[0]=1;
16     for(int i=1;i<=d;++i)fac[i]=fac[i-1]*i%mod;
17     inv[d]=pow(fac[d],mod-2);
18     for(int i=d-1;~i;--i)inv[i]=inv[i+1]*(i+1)%mod;
19     for(int i=1;i<=w;++i)scanf("%lld%lld",&p[i],&t[i]),N=N*pow(p[i],t[i])%mod;
20     for(int i=1;i<=d+1;++i)mx[i][d+2]=(mx[i-1][d+2]+pow(i,d))%mod,mx[i][1]=i;
21     for(int i=1;i<=d+1;++i)for(int j=2;j<=d+1;++j)mx[i][j]=mx[i][j-1]*i%mod;
22     Gauss();
23     for(int i=1;i<=d+1;++i){
24         int base=mx[i][d+2]*pow(N,i)%mod;
25         for(int j=1;j<=w;++j)base=base*(mod+1-pow(p[j],d-i+mod-1))%mod;
26         ans=(ans+base)%mod;
27     }printf("%lld\n",ans);
28 }
I only now caught up six months ago in the mud Meng ah

Guess you like

Origin www.cnblogs.com/hzoi-DeepinC/p/12013657.html