Cattleya number && prufer sequence && BSGS water title set

First talk about a pit BSGS of:

Solutions of the equation A ^ x≡B (mod p)

Need a special judge things => A% p == B% p == 0?

If they are equal then puts ( "1") and vice versa no solution.

Because if A% p = 0, then the item can not be moved, resulting in erroneous BSGS algorithm

Into the title:

Cutler a number (C (2 * n, n) / (n + 1)) 01 for processing arbitrary position in the sequence number 0> of the case 1. .

But know the definition useless, it is important to hit the table to find the law.

Several good at finding out with next_permutation, search and other tools.

Remember that the first few Cattleya number: 1251442132429. (Anyway, you can only find these items)

As for the method for finding, the first of the most simple, modulus can be used Lucas, modulo not high precision.

Like other high-precision of animals hit high precision in addition, do not like to decomposition of the quality factor, data may be small O (n ^ 2) enumeration.

Posted about the code into prime factors:

 1 #include<cstdio>
 2 #include<iostream>
 3 using namespace std;
 4 #define MAXN 4000005
 5 int prime[MAXN],tot,n,frpr[MAXN],fenzi[MAXN],tot1;
 6 void pre()
 7 {
 8     for(int i=2;i<=2*n;i++)
 9     {
10         if(!frpr[i])
11         {
12             frpr[i]=i;
13             prime[++tot]=i;
14         }
15         for(int j=1;j<=tot;j++)
16         {
17             if(prime[j]*i>2*n)break;
18             frpr[prime[j]*i]=prime[j];
19             if(!(i%prime[j]))break;
20         }
21     }
22     return ;
23 }
24 void Get_pr(int x,int opt)
25 {
26     while(x!=1)
27     {
28         if(opt==0)fenzi[frpr[x]]++;
29         else fenzi[frpr[x]]--;
30         x/=frpr[x];
31     }
32     return ;
33 }
34 int main()
35 {
36     int p,ans=1;
37     scanf("%d%d",&n,&p);
38     pre();
39     for(int i=n+2;i<=2*n;i++)Get_pr(i,0);
40     for(int i=1;i<=n;i++)Get_pr(i,1);
41     for(int i=1;i<=tot;i++)
42     {
43         while(fenzi[prime[i]]>0)
44         {
45             ans=1ll*ans*prime[i]%p;
46             fenzi[prime[i]]--;
47         }
48     }
49     cout<<ans<<endl;
50     return 0;
51 }
View Code

Two prufer sequence

N represents nodes n 2-by-point with a reference tree can be demonstrated prufer sequence and the corresponding tree is uniquely determined.

We can get some reasoning:

1. n the number of dots constituting unrooted tree: n ^ (n-2)

2. Determine the degree n points respectively d1, d2 ... no root of the tree number: (n-2) / ((d1-1) * (d2-1) * ...!!)!

3. n points have a rooted tree reference number: n * n ^ (n-2) = n ^ (n-1)

4. degrees of all the nodes and n * 2-2

In addition to counting the number of trees, anything else. . . It lacks the ( heard also optimizes violence enumeration)

 

Guess you like

Origin www.cnblogs.com/hzoi-kx/p/11222748.html