/*有可能这样一种情况:很多次的调用字符转换成数字的函数,不然我也不知道了,参考你的素数表的方法,我也写了一个,AC了*/#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX 1000001
char s[50];
char a[MAX];
int maxlen;
void deal()
{
int i,j;
a[0] = a[1] = '0';
for (i = 2; i <= MAX-1; i++) a[i] = '1';
for (i = 2; i <= MAX-1; i++)
if (a[i] == '1')
for (j = 2; i*j <= MAX-1; j++)
a[i*j] = '0';
}
void work(int head, int len, int tot)
{
int num = 0, i;
num = tot*10;
num += s[head+len-1]-48;
if (head == 0 && len == 6 && a[num] == '0') {printf("NO"); exit(0);}
if (head + len == maxlen && a[num] == '1') {printf("YES"); exit(0);}
if (a[num] == '1') work(head+len, 1, 0);
if (head+len != maxlen && head+len+1 <= maxlen && len+1 <= 6)
work(head, len+1, num);
return;
}
int main()
{
deal();
gets(s);
maxlen = strlen(s);
work(0, 1, 0);
printf("NO\n");
return 0;
}
|