# UOJ#129. 【NOI2015】寿司晚宴

code：

#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
#define pb push_back
using namespace std;

const int maxn = 510;

int p[maxn],pri,xp[maxn],v[maxn];
int cov[maxn];
vector<int>V[maxn];
void get_prime()
{
for(int i=2;i<maxn;i++)
{
if(!v[i]) xp[i]=i,p[++pri]=i;
for(int j=1,k=p[j]*i;k<maxn;j++,k=p[j]*i)
{
xp[k]=xp[i]; v[k]=1;
if(i%p[j]==0) break;
}
}
for(int i=2;i<maxn;i++)
{
for(int j=1;j<=8;j++) if(i%p[j]==0) cov[i]|=1<<j-1;
if(xp[i]>p[8]) V[xp[i]].pb(i);
else V[i].pb(i);
}
}

int n,mod;
inline void add(int &a,const int &b){a+=b;if(a>=mod)a-=mod;}

int main()
{
get_prime();

scanf("%d%d",&n,&mod);

f[0][0]=1; int S=(1<<8)-1;
for(int i=n;i>=2;i--) if(V[i].size())
{
int now=0;
for(int s1=0;s1<=S;s1++)
{
int oth=S-s1;
for(int s2=oth;;s2=(s2-1)&oth)
{
g0[now][s1][s2]=g1[now][s1][s2]=f[s1][s2];
g0[!now][s1][s2]=g1[!now][s1][s2]=0;
if(!s2) break;
}
}
for(int j=0;j<(int)V[i].size();j++) if(V[i][j]<=n)
{
int x=V[i][j]; now=!now;
for(int s1=0;s1<=S;s1++)
{
int oth=S-s1;
for(int s2=oth;;s2=(s2-1)&oth)
{
int &t1=g0[!now][s1][s2];
t1=0;

int &t2=g1[!now][s1][s2];
t2=0;
if(!s2) break;
}
}
}
for(int s1=0;s1<=S;s1++)
{
int oth=S-s1;
for(int s2=oth;;s2=(s2-1)&oth)
{
f[s1][s2]=(g0[now][s1][s2]+g1[now][s1][s2]-f[s1][s2])%mod;
if(f[s1][s2]<0) f[s1][s2]+=mod;
if(!s2) break;
}
}
}

int ans=0;
for(int s1=0;s1<=S;s1++)
{
int oth=S-s1;
for(int s2=oth;;s2=(s2-1)&oth)
{
if(!s2) break;
}
}
printf("%d\n",ans);

return 0;
}


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120