Cod sursa(job #1808565)

Utilizator CodrutLemeniCodrut Lemeni CodrutLemeni Data 17 noiembrie 2016 20:48:43
Problema Dtcsu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.54 kb
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NRDAT 276997
#define N 4000000

using namespace std;

char sir[20];
int mod[]={3682663,1632563,1282653,3182643,2682664,682663};
bool viz[N];

int read_nr(){
    int nr,j;

    scanf("%s",sir);

    for( j=0 , nr=0; sir[j]!=NULL ; j++){
        nr = nr*10 + sir[j] - '0';
    }
    return nr;
}
int nrsol;
int main(){
    long long nr;
    int i,j,q,spy,x;

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


    for(i=0;i<NRDAT;i++){
        scanf("%s",sir);

        for( j=0 , nr=0; sir[j] != NULL ; j++){
            nr = nr*10 + sir[j] - '0';
        }

        if(nr){
            for( j=0 ; j<=5 ; j++){
                viz[ nr % mod[j] ] =1;
            }
        }
    }

    q = read_nr();

    while(q--){
        x = read_nr();
        if(x == 0){
            continue;
        }


        spy=0;
        for(j = 0 ; j <= 5 ; j++ ){
            if(viz[ x % mod[j] ] == 0){
                spy=1;
                break;
            }
        }
        if(spy==1){
            continue;
        }

        while( x % 11 == 0){
            x/=11;
        }
        while( x % 7 == 0 ){
            x/=7;
        }
        while( x % 5 == 0){
            x/=5;
        }
        while(x%3 == 0){
            x/=3;
        }
        while(x%2 == 0){
            x/=2;
        }

        if(x==1 ){
            nrsol++;
        }

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