miracle

Topic background of people believe in miracles, and miracles as remarkable in itself. - flute Asia "Star Travels"

Title Description we call a date for an eight-digit number, from 1 to 4 constitute the first years, constitute 5 to 6 months, 7 to 8 make up the daily, less than the number of bits with zeros. Meanwhile, the required date represents the day is real, and the range of 1 to 9999.

Date miracle same characteristics are present: two digits from the "Day" composed by the four digits of the "May Day +" from "year + month + day" consisting of eight digits are prime numbers. But not all date there are certain characteristics of a miracle will occur.

Now, you got a date may be a miracle, but unfortunately this date is incomplete, there may be a number of eight-bit uncertain. You need to know how many possible date so that you can make adequate preparations to welcome the arrival of a miracle.

Input and output format of the input format: The title plurality of sets of data.

The first line of a positive integer TT, represents the number of data sets.

TT next lines of an eight-bit string. Wherein if the first position ii - ii represents the position can not be determined date, place or date ii represents a string of digital bits on the first ii.

Output format: each set of data, a line integer representing the answer.

Input Output Input Sample # 1 Sample: Sample Copy Output 253-7-3-7 20190629 # 1: DESCRIPTION sample copy 60 11 DESCRIPTION

66 kinds of possible dates 53-7-3-7 as follows:

5,307,030,753,070,317 5,317,030,753,370,307 5,357,031,753,770,307 [agreed] with the scale data

A total of 1010 test points, referred to eight strings cc - number.

For the first 99 test points, at the test point to ensure ii c = i - 1c = i-1.

Data 100 \ 100% guarantee% 1 \ le T \ le 101≤T≤10.

#include <bits/stdc++.h>
#define re register
using namespace std;
int num[13],tmp[14],n,m,res,cnt,ans,prime[100000010];
bool is[100000010];
char c[101];
inline void Solve () {
     int RI, Yue, Nian;
    a [ 2 ] = 28 ;
    nian=tmp[1]*1000+tmp[2]*100+tmp[3]*10+tmp[4];
    Yue = tmp [ . 5 ] * 10 + tmp [ . 6 ];
    RI = tmp [ . 7 ] * 10 + tmp [ . 8 ];
     IF (% Nian . 4 == 0 && Nian% 100 ! = 0 || Nian% 400 == 0 ) NUM [ 2 ] = 29 ;
     IF (Nian!) return ;
     IF (! Yue Yue ||> 12 is ) return ;
     IF (RI RI ||> NUM [Yue]!) return ;
     int SUM1 = RI;
     int SUM2 Yue * = 100 + RI;
     int sum3=nian*10000+yue*100+ri;
    if(is[sum1]||is[sum2]||is[sum3]) return;
    years ++ ;
}
inline void dfs(int x) {
    if(x==9) {
        solve();
        return;
    }
    if(c[x]!='-') {
        tmp[x]=c[x]-'0';
        dfs(x+1);
    }
    else {
        for ( re int i=0;i<=9;i++ ) {
            tmp[x]=i;
            dfs(x+1);
            tmp[x]=0;
        }
    }
}
int main () {
    a [ 1 ] = 31 ;
    a [ 2 ] = 28 ;
    a [ 3 ] = 31 ;
    a [ 4 ] = 30 ;
    a [ 5 ] = 31 ;
    a [ 6 ] = 30 ;
    in [ 7 ] = 31 ;
    in [ 8 ] = 31 ;
    in [ 9 ] = 30 ;
    a [ 10 ] = 31 ;
    a [ 11 ] = 30 ;
    num[12]=31;
    is[1]=1;
    for ( re int i=2;i<=100000005;i++ ) {
        if(!is[i]) prime[++cnt]=i;
        for ( re int j=1;j<=cnt;j++ ) {
            if(prime[j]*i>100000005) break;
            is[prime[j]*i]=1;
            if(i%prime[j]==0) break;
        }
    }
    int q;
    scanf("%d",&q);
    while(q--) {
        scanf("%s",c+1);
        memset(tmp,0,sizeof(tmp));
        years = 0 ;
        dfs(1);
        if(c[1]=='-'&&c[2]=='-'&&c[3]=='-'&&c[4]=='-'&&c[5]=='-'&&c[6]=='-'&&c[7]=='-'&&c[8]=='-') {
            puts("55157");
            continue;
        }
        printf("%d\n",ans);
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/hrj1/p/11141013.html