Cod sursa(job #1808588)

Utilizator CodrutLemeniCodrut Lemeni CodrutLemeni Data 17 noiembrie 2016 21:10:06
Problema Dtcsu Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.77 kb
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
//#include <string.h>
#include <cstring>
#include <bitset>
#define NRDAT 276997
#define N 4000000

using namespace std;

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

long long read_nr(){
    long long nr,j;

    gets(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,x;
    int i,j,q,spy;

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


    for(i=0;i<NRDAT;i++){
        gets(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;
        }
        x /= (x^(x-1)) & x;

        while( (x / 11)*11 == x){
            x/=11;
        }
        while((x / 49)*49 == x){
            x/=49;
        }
        if( (x / 7)*7 == x ){
            x/=7;
        }
        while( (x / 25)*25 == x){
            x/=25;
        }

        if( (x / 5 )*5 == x ){
            x/=5;
        }


        while((x / 9)*9 == x){
            x/=9;
        }
        if((x / 3)*3 == x){
            x/=3;
        }


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

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