JZPKIL: Mobius inversion, Bernoulli numbers, Miller_Rabin, Pollard_Rho

$Description:$

Given $ n, x, y $, seeking $ \ sum \ limits_ {i = 1} ^ {n} gcd (i, n) ^ x lcm (i, n) ^ y $

$ X, y \ the $ 3,000, $ n \ the $ 10 ^ {18}, $ mod = 10 ^ 9 + 7 $

Quite a long time no one wrote a blog for the individual, but this is really the big question God. (Recently brightest Great God is always hanging up questions explosion hammer)

This formula seems very simple at first glance, the more desperate of the two-step.

First $ gcd $ and $ lcm $ multiply the number of the original product.

$=\sum\limits_{i=1}^{n} gcd(i,n)^{x-y} (in)^y$

$=n^y\sum\limits_{i=1}^{n} gcd(i,n)^{x-y} i^y$

$=n^y \sum\limits_{p|n} \sum\limits_{i=1}^{n} [gcd(i,n)=p]p^{x-y} i^y$

$=n^y \sum\limits_{p|n} \sum\limits_{i=1}^{\frac{n}{p}} [gcd(i,\frac{n}{p})] p^x i^y $

$=n^y \sum\limits_{p|n} p^x \sum\limits_{i=1}^{\frac{n}{p}} i^y \sum\limits_{d|i \ and \ d|\frac{n}{p} } \mu(d)$

$=n^y \sum\limits_{p|n} p^x \sum\limits_{d|\frac{n}{p} } d^y \mu(d)\sum\limits_{i=1}^{\frac{n}{pd}} i^y$

Of no more. . . ? But in the end we see the familiar face of natural numbers and power. Anyway, certainly Suan Bule, so to say first substitution with Bernoulli numbers.

Bernoulli used here is a positive number $ B_i ^ + $. Compared to conventional Bernoulli $ B_1 = - \ frac {1} {2} $, positive Bernoulli $ B_1 ^ + = \ frac {1} {2} $

The remaining items are the same, so the formula they use are not the same.

$\sum\limits_{i=0}^{n} i^k =\frac{1}{k+1} \sum\limits_{i=0}^{k} C_{k+1}^{i} B_i (n+1)^{k+1-i} =\sum\limits_{i=0}^{k} C_{k+1}^{i} B_i^+ n^{k+1-i}$

In most cases the latter still looks like a number of easy to use.

However, because this is the first real use Bernoulli numbers, so another method for finding records about.

Many use the recursive time $ O (n ^ 2) $ also be acceptable:

$B_0=1,\sum\limits_{i=0}^{n} B_i C_{n+1}^{i} =0$,也即$B_n=\frac{1}{n} \sum\limits_{i=0}^{n-1} B_i C_{n+1}^{i}$

However, sometimes the card, can be used to generate a polynomial function of the knowledge of the above formula of one of the following to obtain a very nice conclusion: $ B (x) = \ frac {x} {e ^ x-1} $

Write a polynomial exp can do $ O (n \ log \ n) $.

Then, after completion of required regardless of which method to use to take positive $ B_1 $ get better with a number of positive Bernoulli.

So, after the return of this problem, we have a positive Bernoulli numbers substitution:

$=n^y \sum\limits_{p|n}p^x \sum\limits_{d|\frac{n}{p}} d^y \mu(d) \frac{1}{y+1} \sum\limits_{i=0}^{y} C_{y+1}^{i} B_i^+ (\frac{n}{pd})^{y+1-i}$

$=\frac{n^y}{y+1} \sum\limits_{i=0}^{y} C_{y+1}^{i} B_i^+ \sum\limits_{p|n} p^x \sum\limits_{d|\frac{n}{p}} d^y \mu(d) (\frac{n}{pd})^{y+1-i}$

Then I get enough for a long time in front of this formula, the result is more and more do not.

However, stop and take a closer look this formula, the most troublesome relationship is divisible, so after two and look at style, this form is convolution?

A closer look will find that they are the product of several functions. This is good, so we can then function value is multiplied by the contribution of the entire $ n $ for each germplasm FACTOR.

But why should break down? In fact, mainly utilized appear inside a function of $ \ mu $, if only because the $ p $ contain a factor, then the whole equation will only have value $ 0 and $ p ^ 1 $ in $ p ^.

$=\frac{n^y}{y+1}\sum\limits_{i=0}^{y} C_{y+1}^{i} B_i^+ \prod\limits_{p^k|n} \sum\limits_{t=0}^{k} (p^t)^x \sum\limits_{u=0}^{min(k-t),1} (p^u)^y \mu(p^u) (p^{k-t-u})^{y+1-i}$

When only $ k = t $ special, $ u $ can not take $ 1 $. The remaining cases are the same, divide $ u = 0 $ and $ u = 1 $ considerations listed formula:

$=\frac{n^y}{y+1}\sum\limits_{i=0}^{y} C_{y+1}^{i} B_i^+ \prod\limits_{p^k|n} \sum\limits_{t=0}^{k-1} p^{tx} (p^{(k-t)(y+1-i)}-p^{y+(k-t-1)(y+1-i)} + p^{kx}) $

This formula can forget. Enumeration outermost $ i $, the upper bound $ y $, and the number of prime factors enumerated inner layer is $ O (log \ n) $ level. Fast power of $ O (log) $ count. The complexity of the legal and often a little card.

This will not speak, the key is begs the question: how prime factor decomposition ah?

That's $ Pollard \ Rho $ in pot.

This understanding is not only about deep mouth Hu.

We require $ $ n-prime factors, which do not, then the next best thing we find n-$ $ $ p $ a factor then recursively $ p $ and $ \ frac {n} {p} $ seek factor.

Recursion is this border is a prime number, then it is the number of former prime factors. Sentenced prime number sets a $ Miller \ Rabin $ complexity is acceptable.

But now the question is how to quickly find a factor of a number?

The use of the birthday paradox, we now find a direct factor is very difficult, then we Some random number and then twenty-two do worse.

There is a random number generation mechanism thereof is unknown: $ x_i = x_ {i-1} ^ 2 + c (mod \ n) $. c is a random constant. Many explanations are indeed random in a statement this stuff, so why not use the $ rand () $ it?

Puzzled, Suida Liu. However, this is only after a modulo function parameter is always into the circulation, into the circulation section to timely out.

Then leads to the Floyd $ $ Hare judgment of the ring, however, and do not have access omitted.

The last method is widely adopted is doubled, it is a somewhat iterative deepening mean?

Because of the complexity of the $ gcd $ is $ O (log) $, the complexity will be very slow, so how can we do as little as a few $ gcd $?

We can make the difference between a random number of adjacent items, multiplies them together, and if one of the $ n $ non-$ gcd $ 1, then after the final multiplicative $ gcd $ 1 will not be

How many times do then every once $ gcd $ better? Previous experience tells us: $ 127 $. Well, I remember so be it.

Why have iterative deepening / doubling it? For any prime number because we have run $ 127 $ times too wasteful, let's try once okay, then 2 times, then four times. . . If you find it directly out.

O-do item difference in the end is how to increase the probability of this we do not know. Be it practice makes perfect.

However, if you face a random black c regardless of how many times the run, into the ring still can not find the factor, then we should in fact be promptly jump out of. But it looks like there is no such situation (face not black enough)

So I will use the so confusedly. So the question can be done.

Guess you like

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