Poj1091: flea [anti-DDoS principle]

Source: Internet
Author: User
Chinese questions are not translated

Idea: Let us assume that the flea chooses X1 first card and X2 second card... N x n cards, xn + 1 card with M reading, then the equation can be listed: A1 * X1 + A2 * X2 +... + An * xn + M * x (n + 1) = 1

As you can jump left and right, the question is to ask if the above indefinite equation has a solution? The answer and its proof can be found in any number theory book. It must be (A1, A2, A3... An, m) | 1 is A1, A2, A3... In this way, the question becomes: There are n + 1 positive integers, the maximum number of which is m, and ask how many of the sequences that meet the conditions are mutually qualitative.

Many of the mathematical combinations are difficult, but difficult. Consider how many of the largest commonalities on the back of the question is not 1? First, let's take M decomposition as a prime factor. Every factor of M can be considered as a set. The element in the set is a sequence of the maximum common divisor of this factor, the answer to this question is all the elements that are integrated in a set.

Finally, the total number of M ^ N minus the maximum number of public appointments is not 1, and the result is the number of mutual quality.

By the way, although it is part of the set theory, it is often used to prove the number theory problem. It seems to be used to derive the Euler's function formula at the earliest.

# Include <cstdio>

# Include <string>

# Include <iostream>

# Include <math. h>

# Define ll _ int64

Using namespace STD;

Llfactor [100000], H = 0, stack [100000], Top = 0, MT, NT, ret1;

Ll quickpow (ll n, ll m)

{

Ll ret = 1;

While (m)

{

If (M & 1) RET * = N;

N * = N;

M> = 1;

}

Return ret;

}

Void DFS (ll step, ll now, ll layer, ll num)

{

If (step = Layer) {ret1 + = quickpow (MT/num, NT); return ;}

For (INTI = now + 1; I <= H-layer + step + 1; I ++) DFS (Step + 1, now + 1, layer, num * factor [I]);

}

Int main ()

{

Ll N;

Scanf ("% i64d % i64d", & nt, & mt );

N = MT;

While (N & 1) = 0) {H = 1; factor [H] = 2; n >>= 1 ;}

Ll q = SQRT (N );

For (ll I = 3; I <= Q & n! = 1; I + = 2)

{

If (N % I = 0) factor [++ H] = I;

While (N % I = 0) n = N/I;

}

If (n! = 1) factor [++ H] = N;

Ll ans = 0, flag =-1;

For (ll I = 1; I <= H; I ++)

{

Flag * =-1;

Top = ret1 = 0;

DFS (0, 0, I, 1 );

Ans + = ret1 * flag;

}

Printf ("% i64d \ n", (LL) quickpow (MT, NT)-ans );

Return 0;

}

Poj1091: flea [anti-DDoS principle]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.