Cod sursa(job #1806423)

Utilizator CodrutLemeniCodrut Lemeni CodrutLemeni Data 15 noiembrie 2016 12:16:52
Problema Dtcsu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.45 kb
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
//#define NR 276997
#define NR 276997
#define P1 73
#define P2 51
#define MOD1 46507
#define MOD2 46511

using namespace std;

bool hash1[MOD1];
bool hash2[MOD2];

char sir[25];
int h1;
int h2;
long long get_nr( ){
    static int len,i;
    static long long nr;

    scanf("%s",sir);
    len = strlen(sir);

    h1=h2=nr=0;
    for(i = 0 ; i < len ; i++){
        nr = nr*10 + sir [i] -'0';
        h1 = (h1*P1 +sir[i]-'0') %MOD1;
        h1 = (h1*P2 +sir[i]-'0') %MOD2;
    }
    return nr;
}

int main(){
    int i ;
    long long q,x;
    int nrsol=0;

    freopen("dtcsu.in","r",stdin);
    freopen("dtcsu.out","w",stdout);

    for(i=0 ;i <NR ;i++){
        x=get_nr();
        hash1[ h1 ] = true;
        hash2[ h2 ] = true;
    }
    q=get_nr();

    for(i=0; i<q;i++){
        x=get_nr();
        if( hash1[  h1 ] == true && hash2[  h2 ] == true){
            while( x%2 ==0 ){
                x/=2;
            }
            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){
                nrsol++;
            }
        }
    }


    printf("%d",nrsol);
    return 0;
}