Interestingly, the number of columns unique decomposition theorem Cartland number +

Question:
We call a length \ (2n \) the number of columns is interesting, if and only if the number of columns meet the following three conditions:

(1) which is from \ (1 \) to \ (2N \) co \ (2N \) a permutation of the integers { \ (Ai \) };

(2) satisfying all of the odd term \ (A1 <A3 <... <-A2n are. 1 \) , satisfies all the even term \ (A2 <A4 <... <A2n are \) ;

(3) any two adjacent \ (A2i-1 \) and \ (A2i (1≤i≤n) \) satisfies less than odd-numbered even-numbered, namely: \ (. 1 to A2i-<to A2i \) .

The task now is: for a given \ (n-\) , the number of requests of different length \ (2N \) interesting series. Because the final answer may be large, so only the required output answer \ (mod P \) values.

Solution:
$ 1,251,442 $
odd-even number less than \ (Drawing> = pop \) This is a number Cattleya

We should be solved by what formula
$ \ FRAC {c_ {2n} ^ the n-} {the n-+ 1} $ = \ (\ FRAC {2n!} {The n-! * The n-!} \) * \ (\ FRAC {1} { +. 1} n-\) = \ (\ + prod_ {n-2}} ^ {n-2 ** \)

This question is still not finished but
you will find it is not necessarily a prime number modulus so you use extendedlucas

Well, in fact, it is the only decomposition theorem to reduce fractions

Although I do not know why you can about minute
to open my first prime factor for the number of times each screen \ (T 50 \)
after the pointing hyh
I found the discussion can move forward from the decomposition of each number \ (sqrt \) level

code:

#include<stdio.h>
#include<iostream>
using namespace std;
#define maxnn 2000100
#define ll long long
ll zhi[maxnn];
ll n,p;
ll phi[maxnn];
ll cnt[maxnn];
ll len=0;
ll is[maxnn];
void init()
{
    phi[1]=1;
    for(ll i=2;i<=2000000;i++)
    {
        if(!phi[i])
            zhi[++len]=i;
        for(int j=1;j<=len&&zhi[j]*i<=2000000;j++)
        {
            phi[zhi[j]*i]=1;
            if(i%zhi[j]==0) break;
        }
    }
}
void iiit(){
  
    for(ll i=2*n;i>=1;i--)
    {
        if(is[i])
    {
        if(zhi[lower_bound(zhi+1,zhi+len+1,i)-zhi]==i) continue;
        for(int j=2;j*j<=i;j++)
        {
            if(i%j==0)
            {
                is[j]+=is[i];
                is[i/j]+=is[i];
                break;
            }
        }
    }
    }
    for(int i=1;i<=len&&zhi[i]<=2*n;i++)
    {
        if(is[zhi[i]]) cnt[zhi[i]]+=is[zhi[i]];
    }
}
ll ksm(ll a,ll b)
{
    ll ans=1;
    while(b)
    {
        if(b&1) ans=ans*a%p;
        a=a*a%p;
        b>>=1;
    }
    return ans;
}
int main(){
    cin>>n>>p;
    for(ll i=n+2;i<=2*n;i++) is[i]=1;
    for(ll i=1;i<=n;i++) is[i]=-1;
    init();
    iiit();
    ll tot=1;
    for(ll i=1;i<=len&&zhi[i]<=2*n;i++)
    {
        if(cnt[zhi[i]]) tot=tot*ksm(zhi[i],cnt[zhi[i]])%p;
    }
    cout<<tot%p;
}

Guess you like

Origin www.cnblogs.com/OIEREDSION/p/11495105.html