Cod sursa(job #1806420)

Utilizator CodrutLemeniCodrut Lemeni CodrutLemeni Data 15 noiembrie 2016 12:10:36
Problema Dtcsu Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.23 kb
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
//#define NR 276997
#define NR 276997
#define MOD1 7919

using namespace std;

bool hash1[MOD1];

char sir[25];

long long get_nr( ){
    static int len,i;
    static long long nr;

    scanf("%s",sir);
    len = strlen(sir);
    nr=0;
    for(i = 0 ; i < len ; i++){
        nr = nr*10 + sir [i] -'0';
    }
    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[ x % MOD1 ] = true;
    }
    q=get_nr();

    for(i=0; i<q;i++){
        x=get_nr();
        if( hash1[  x % MOD1 ] == 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;
}