11.3 上午考试
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> using namespace std; int l,tot,topt; int f[1<<24]; int ans[200010]; char s[20000010]; int main() { freopen("ab.in","r",stdin); freopen("ab.out","w",stdout); scanf("%s",s+1); l=strlen(s+1); int r=ceil(log(l)/log(2)); for(int i=1;i<=l;i++) { int x=0; for(int j=i;j<=i+r-1&&j<=l;j++) { x=x*2+s[j]-'A'; f[x+(1<<j-i+1)]=1; } } int now,len=1,flag=0; while(1) { now=0;int ha=1<<len; while(now<=ha-1) { if(f[now+ha]==0) { ans[0]=len;flag=1; while(now) { ans[len]=now%2; now/=2;len--; } break; } now++; } len++; if(flag)break; } for(int i=1;i<=ans[0];i++) printf("%c",ans[i]+'A'); printf("\n"); return 0; }
/* 60分暴力 */ #include<iostream> #include<cstdio> #include<cstring> #define LL long long using namespace std; LL n,p,a,b,tot,ans; LL prime[1000010]; int f[10000010]; LL init() { LL x=0,f=1;char c=getchar(); while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();} return x*f; } void prepare(LL x) { for(LL i=2;i<=x;i++) { if(!f[i])prime[++tot]=i; for(LL j=1;j<=tot&&prime[j]*i<=x;j++) { f[prime[j]*i]=1; if(i%prime[j]==0)break; } } } int main() { freopen("prime.in","r",stdin); freopen("prime.out","w",stdout); p=init();a=init();b=init(); prepare(p); for(int i=a;i<=b;i++) f[i-a+1]=i; for(int i=1;i<=tot;i++) { int l=a/prime[i]*prime[i]; for(int j=l;j<=b;j+=prime[i]) { if(j-a+1<=0)continue; while(f[j-a+1]%prime[i]==0) f[j-a+1]/=prime[i]; } } for(int i=a;i<=b;i++) if(f[i-a+1]>1)ans++; cout<<ans<<endl; return 0; }
/* 应该是正解 只要不爆栈(考试时老师设置了8M的栈) */ #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; int n,p,a,b,tot,ans; int prime[1000010]; int f[10000010]; int init() { int x=0,f=1;char c=getchar(); while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();} return x*f; } void prepare() { for(int i=2;i<=p;i++) { if(!f[i])prime[++tot]=i; for(int j=1;j<=tot&&prime[j]*i<=p;j++) { f[prime[j]*i]=1; if(i%prime[j]==0)break; } } } int judge(int x,int mx) { for(int i=2;i*i<=x;i++) { if(x%i==0) { if(i>mx)return 0; while(x%i==0)x/=i; } } if(x>mx)return 0; return 1; } int dfs(int l,int r,int x) { if(l>r)return 0; if(x==0)return l==1; if(r<=prime[x])return r-l+1; if(l==r)return judge(l,prime[x]); return dfs(l,r,x-1)+dfs((l-1)/prime[x]+1,r/prime[x],x); } int main() { freopen("prime.in","r",stdin); freopen("prime.out","w",stdout); p=init();a=init();b=init(); prepare(); cout<<b-a+1-dfs(a,b,tot)<<endl; return 0; }
暂无正解