Cod sursa(job #1032297)

Utilizator tzipleatudTudor Tiplea tzipleatud Data 15 noiembrie 2013 19:13:07
Problema Dtcsu Scor 0
Compilator cpp Status done
Runda FMI No Stress 4 Marime 2.25 kb
#include <fstream>
#include <cstdio>

using namespace std;

FILE *fin=fopen("dtcsu.in", "r");
FILE *fout=fopen("dtcsu.out", "w");

const int maxb=100000;
int ptr=0;
char buff[maxb];

long long GetLong ()
{
    long long nr=0;

    while (buff[ptr]<'0' || buff[ptr]>'9')
        if ((++ptr)>=maxb)
        {
            ptr=0;
            fread(buff, 1, maxb, fin);
        }

    while (buff[ptr]>='0' && buff[ptr]<='9')
    {
        nr=nr*10+buff[ptr]-'0';
        if ((++ptr)>=maxb)
        {
            ptr=0;
            fread(buff, 1, maxb, fin);
        }
    }

    return nr;
}

int N=276997, Q;
long long X, VM=1LL*1000000000*1000000000;
long long Pow[20][70], S[6];

void Divide (long long& X, int p)
{
    int P=0, U=S[p], M, ANS=0;

    while (P<=U)
    {
        M=(P+U)/2;
        if (X%Pow[p][M]==0)
        {
            ANS=M;
            P=M+1;
        }
        else
            U=M-1;
    }

    X/=Pow[p][ANS];
}

int main ()
{
    Pow[2][0]=Pow[3][0]=Pow[5][0]=Pow[7][0]=Pow[11][0]=1;
    S[2]=1;
    Pow[2][1]=2;
    for (; ;)
    {
        ++S[2];
        Pow[2][S[2]]=2LL*Pow[2][S[2]-1];
        if (Pow[2][S[2]]>VM/2LL)
            break;
    }
    S[3]=1;
    Pow[3][1]=3;
    for (; ;)
    {
        ++S[3];
        Pow[3][S[3]]=3LL*Pow[3][S[3]-1];
        if (Pow[3][S[3]]>VM/3LL)
            break;
    }
    S[5]=1;
    Pow[5][1]=5;
    for (; ;)
    {
        ++S[5];
        Pow[5][S[5]]=5LL*Pow[5][S[5]-1];
        if (Pow[5][S[5]]>VM/5LL)
            break;
    }
    S[7]=1;
    Pow[7][1]=7;
    for (; ;)
    {
        ++S[7];
        Pow[7][S[7]]=7LL*Pow[7][S[7]-1];
        if (Pow[7][S[7]]>VM/7LL)
            break;
    }
    S[11]=1;
    Pow[11][1]=11;
    for (; ;)
    {
        ++S[11];
        Pow[11][S[11]]=11LL*Pow[11][S[11]-1];
        if (Pow[11][S[11]]>VM/11LL)
            break;
    }

    for (int i=1; i<=N; i++)
        X=GetLong();

    Q=GetLong();
    int ANS=0;
    for (int i=1; i<=Q; i++)
    {
        X=GetLong();
        Divide(X, 2);
        Divide(X, 3);
        Divide(X, 5);
        Divide(X, 7);
        Divide(X, 11);
        if (X<=1) ANS++;
    }

    fprintf(fout, "%d\n", ANS);

    return 0;
}