Cod sursa(job #1034487)

Utilizator visanrVisan Radu visanr Data 17 noiembrie 2013 21:07:25
Problema Dtcsu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.37 kb
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iomanip>
using namespace std;

const int Fact[3] = {2437, 2441, 2467};
const int Mod[3] = {100001, 100003, 100009};

int Is[100010], T, Ans;
long long N;

const int MaxB = 10000;
char Buf[MaxB];
int Ptr;

inline long long Get()
{
    long long Ans = 0;
    while(!isdigit(Buf[Ptr]))
        if(++ Ptr >= MaxB)
            fread(Buf, 1, MaxB, stdin), Ptr = 0;
    while(isdigit(Buf[Ptr]))
    {
        Ans = Ans * 10 + Buf[Ptr] - '0';
        if(++ Ptr >= MaxB)
            fread(Buf, 1, MaxB, stdin), Ptr = 0;
    }
    return Ans;
}

int Codif(int Index, long long Num)
{
    int X = 0;
    while(Num)
    {
        X = (1LL * X * Fact[Index] + Num % 10) % Mod[Index];
        Num /= 10;
    }
    return X;
}

int main()
{
    freopen("dtcsu.in", "r", stdin);
    freopen("dtcsu.out", "w", stdout);
    fread(Buf, 1, MaxB, stdin);

    for(int i = 1; i <= 13/*276997*/; ++ i)
    {
        long long X = Get();
        for(int j = 0; j < 3; ++ j)
            Is[Codif(j, X) % 100010] = 1;
    }

    T = Get();
    for(; T; T --)
    {
        N = Get();
        bool OK = 1;
        for(int j = 0; j < 3 && OK; ++ j)
            if(!Is[Codif(j, N) % 100010])
                OK = 0;

        if(OK) Ans += OK;
    }

    printf("%i\n", Ans);
}