1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
#include<ctime> #include<cstdio> #include<cstring> #include<cstdlib> #include<map> #include<set> #include<queue> #include<deque> #include<stack> #include<bitset> #include<vector> #include<algorithm> #include<iostream> using namespace std; #ifdef DEBUG const int LOCAL=1; #else const int LOCAL=0; #endif
namespace mine { typedef long long ll; const int INF=0x3f3f3f3f;
const int MOD=1000000001; int (int x,int y) { x+=y;if(x>=MOD) x-=MOD; return x; } bool v[110000]; int bin[30],the[30]; int f[2][1<<22]; vector<int> sta[30]; bool okay[1<<22]; void main() { bin[0]=1;for(int i=1;i<=20;i++) bin[i]=bin[i-1]<<1; the[0]=1;for(int i=1;i<=20;i++) the[i]=the[i-1]*3;
for(int s=0;s<bin[20];s++) { okay[s]=!(s&(s<<1)); if(okay[s]) { int mx=0;for(int t=1;t<=20;t++) if(s&bin[t]) mx=t; for(int t=mx;t<=20;t++) sta[t+1].push_back(s); } }
int n;scanf("%d",&n); int ans=1; for(int st=1;st<=n;st++) if(!v[st]) { v[st]=1; int ln=0;while(st*the[ln+1]<=n) ln++,v[st*the[ln]]=1; ln++;
for(int t=0;t<(int)sta[ln].size();t++) f[0][sta[ln][t]]=1;
int r; for(r=1;st*bin[r]<=n;r++) { int ln2=0,st2=st*bin[r];v[st2]=1; while(st2*the[ln2+1]<=n) ln2++,v[st2*the[ln2]]=1; ln2++;
for(int t=0;t<(int)sta[ln].size();t++) if(f[(r-1)&1][ sta[ln][t] ]) { int s1=sta[ln][t],oth=bin[ln2]-1-(s1&(bin[ln2]-1));
for(int s2=oth;s2>0;s2=(s2-1)&oth) if(okay[s2]) f[r&1][s2]=add(f[r&1][s2],f[(r-1)&1][s1]); f[r&1][0]=add(f[r&1][0],f[(r-1)&1][s1]);
f[(r-1)&1][s1]=0; } ln=ln2; } int cnt=0; for(int t=0;t<(int)sta[ln].size();t++) cnt=add(cnt,f[(r-1)&1][sta[ln][t]]),f[(r-1)&1][sta[ln][t]]=0; ans=(ll)ans*cnt%MOD; } printf("%d",ans); } }; int main() { srand(time(0)); mine::main(); }
|
近期评论