Skip to content

Instantly share code, notes, and snippets.

@SilverRainZ
Created October 5, 2014 14:02
Show Gist options
  • Save SilverRainZ/27e9ade22b66633accba to your computer and use it in GitHub Desktop.
Save SilverRainZ/27e9ade22b66633accba to your computer and use it in GitHub Desktop.
9528 潜伏
#include<cstdio>
#include<cstring>
bool pr[110];
void init()
{
int i,j;
memset(pr,true,sizeof(pr));
pr[0]=pr[1]=false;
for(i=1;i<100;i++)if(pr[i])
{
for(j=2;i*j<=100;j++)
pr[i*j]=false;
}
}
int n;
int a[100010];
char s[100010];
void init2()
{
int i,pp;
int len=strlen(s);
a[len+1]=a[len]=-1;
pp=0;
for(i=len-1;i>=0;i--)
{
pp=pp/10+(s[i]-'0')*10;
if(pp>10&&pr[pp])
a[i]=pp;
else
a[i]=a[i+1];
}
}
int main()
{
// freopen("6.in","r",stdin);
// freopen("6.out","w",stdout);
int i,j;
init();
scanf("%s%d",s,&n);
init2();
for(i=0;i<n;i++)
{
scanf("%d",&j);
printf("%d\n",a[j-1]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment