Created
October 5, 2014 14:18
-
-
Save SilverRainZ/6af12c9f8e1c16d140a8 to your computer and use it in GitHub Desktop.
9528 潜伏2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <math.h> | |
int main() | |
{ | |
int prime[100]; | |
for (int i = 10; i <= 99; i++) | |
{ | |
int f = 1; | |
for (int j = 2; j <= sqrt(i); j++) | |
if (i % j == 0) {f = !f; break;} | |
prime[i] = f; | |
} | |
//for (int i = 10; i <= 99; i++) if (prime[i]) printf("%d ",i); | |
char s[100005]; | |
int flag[100005]; | |
gets(s); | |
int n = strlen(s); | |
flag[n] = -1; | |
int elem = -1; | |
for (int i = n - 2; i >= 0; i--) | |
{ | |
int tmp = (s[i] - 48)*10 + s[i + 1] - 48; | |
if (prime[tmp] == 1) elem = tmp; | |
flag[i + 1] = elem; | |
} | |
int m,v; | |
scanf("%d",&m); | |
for (int i = 1; i < m; i++) | |
{ | |
scanf("%d",&v); | |
printf("%d\n",flag[v]); | |
} | |
scanf("%d",&v); | |
printf("%d",flag[v]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment