# bzoj 1485: [HNOI2009]有趣的数列

### Description

(1)它是从1到2n共2n个整数的一个排列{ai};
(2)所有的奇数项满足a1<a3<…<a2n-1，所有的偶数项满足a2<a4<…<a2n;
(3)任意相邻的两项a2i-1与a2i(1≤i≤n)满足奇数项小于偶数项，即：a2i-1<a2i。

### solution

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#define RG register
#define il inline
#define iter iterator
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
typedef long long ll;
const int N=2000005;
int n,prime[N],num=0,vis[N],t[N],P,lim;
void priwork(){
for(int i=2;i<=lim;i++){
if(!vis[i])prime[++num]=i,vis[i]=i;
for(int j=1;j<=num && prime[j]*i<=lim;j++){
vis[i*prime[j]]=prime[j];
if(i%prime[j]==0)break;
}
}
}
void work()
{
scanf("%d%d",&n,&P);
lim=n<<1;
priwork();
for(int i=n+2;i<=lim;i++){
int j=i;
while(j>1)t[vis[j]]++,j/=vis[j];
}
for(int i=2;i<=n;i++){
int j=i;
while(j>1)t[vis[j]]--,j/=vis[j];
}
ll ans=1;
for(int i=2;i<=lim;i++)
for(int j=1;j<=t[i];j++)
ans*=i,ans%=P;
printf("%lld\n",ans);
}

int main()
{
work();
return 0;
}


posted @ 2017-10-29 18:32  PIPIBoss  阅读(125)  评论(0编辑  收藏  举报