Cod sursa(job #1333671)

Utilizator AeroHHorea Stefan AeroH Data 3 februarie 2015 14:35:37
Problema Dtcsu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.36 kb
#include <fstream>

using namespace std;

ifstream f ("dtcsu.in");
ofstream g ("dtcsu.out");
int rasp;
char h[5][1100];
///1009 1013 1019 1021 1031 1033 1039 1049 1051 1061 1063 1069 1087 1091 1093 1097

bool verif(long long int x)
    {
        while(!(x&1))x>>=1;
        while(x%3==0)x/=3;
        while(x%5==0)x/=5;
        while(x%7==0)x/=7;
        while(x%11==0)x/=11;
        if (x==1)
            {
                ++rasp;
                return 1;
            }
        return 0;
    }

bool hash(long long int x)
    {
        if (!h[0][x % 1009])
            return 0;
        x>>=5;
        if (!h[1][x % 1013])
            return 0;
        x>>=5;
        if (!h[2][x % 1019])
            return 0;
        x>>=5;
        if (!h[3][x % 1021])
            return 0;
        x>>=5;
        if (!h[4][x % 1031])
            return 0;

        return 1;
    }
void add(long long int x)
    {
        h[0][x % 1009]|=1;

        x>>=5;
        h[1][x % 1013]|=1;

        x>>=5;
        h[2][x % 1019]|=1;

        x>>=5;
        h[3][x % 1021]|=1;

        x>>=5;
        h[4][x % 1031]|=1;
    }


int main ()
{
int N=22;
long long int x;
while(N--)
    {
        f>>x;
        add(x);
    }
f>>N;
while(N--)
    {
        f>>x;
        if (hash(x))
            verif(x);
    }
g<<rasp;

return 0;
}