Cod sursa(job #1854067)

Utilizator georgerapeanuRapeanu George georgerapeanu Data 22 ianuarie 2017 13:04:56
Problema Dtcsu Scor 20
Compilator cpp Status done
Runda antr5 Marime 1.27 kb
#include <cstdio>
#include <bitset>
#define LEN 4096
using namespace std;
FILE *f;
FILE *g=fopen("dtcsu.out","w");
int rez;
long long Q,val;
bitset <10000005> B;
int hcode[]={666013,191723,234567,456565};
char buffer[LEN];
int ind;
void readinit(char *c)
{
    f=fopen(c,"r");
    ind=LEN-1;
}
char getch()
{
    ind++;
    if(ind==LEN) {fread(buffer,1,LEN,f);ind=0;}
    return buffer[ind];
}
long long getnext()
{
    char c;
    c=getch();
    long long nr=0;
    while(!isdigit(c))
        c=getch();
    while(isdigit(c))
    {
        nr=nr*10+c-'0';
        c=getch();
    }
    return nr;
}
int main()
{
    readinit("dtcsu.in");
    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)
            {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;
}