Cod sursa(job #1853836)

Utilizator georgerapeanuRapeanu George georgerapeanu Data 22 ianuarie 2017 10:07:20
Problema Dtcsu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <cstdio>
#include <bitset>
using namespace std;
FILE *f=fopen("dtcsu.in","r");
FILE *g=fopen("dtcsu.out","w");
char buffer[30];
int rez;
long long Q,val;
bitset <10000005> B;
int hcode[]={666013,191723,234567,456565};
long long getnext()
{
    fgets(buffer+1,30,f);
    int poz=1;
    long long nr=0;
    while('0'<=buffer[poz]&&buffer[poz]<='9'){nr=nr*10+buffer[poz]-'0';poz++;}
    return nr;
}
int main()
{
    for(int i=1;i<=276997;i++)
    {
        val=getnext();
        for(int j=0;j<4;j++)
            B[val%hcode[j]]=1;
    }
    Q=getnext();
    for(int i=1;i<=Q;i++)
    {
        val=getnext();
        if(!val) continue;
        bool ok=0;
        for(int j=0;j<4&&!ok;j++)
            if(B[val%hcode[j]]) ok=1;
        if(!ok)
            {rez++;continue;}
        val=val/(val&(val^(val-1)));
        while(val%11==0) val/=11;
        while(val%7==0) val/=7;
        while(val%5==0) val/=5;
        while(val%3==0) val/=3;
        if(val==1) rez++;
    }
    fprintf(g,"%d",rez);
    return 0;
}