Cod sursa(job #1034668)

Utilizator geniucosOncescu Costin geniucos Data 17 noiembrie 2013 23:21:50
Problema Dtcsu Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.5 kb
#include<cstdio>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;
ifstream f("dtcsu.in");
#define MaxChar 10000
#define verf ( (++CharB==MaxChar) ? ( f.read(Buffer,MaxChar),CharB=0 ) : (1) )
int CharB;
char ch,Buffer[MaxChar],sir[30];
void cit(long long &a)
{
    a=0;
    for (;!((Buffer[CharB]>='0'&&Buffer[ CharB ]<='9')||(Buffer[CharB]=='-'));verf);
    for (a=0;(Buffer[CharB]>='0'&&Buffer[CharB]<='9');a*=10,a+=(Buffer[CharB]-'0'),verf);
}
////////////////////////////////////////////////////
int sol,i,nr,T,p[6];
long long V,INF;
vector < long long > v[17007];
vector < long long > :: iterator it;
int Lin(long long P)
{
    int lin=((P&34564)+P^27654-P^32876857+P)%7007;
    if(lin<0) lin+=7007;
    return lin;
}
void Push(long long P)
{
    v[Lin(P)].push_back(P);
}
void back(int poz,long long P)
{
    int i;
    if(poz==5)
    {
        nr++;
        Push(P);
        return;
    }
    back(poz+1,P);
    for(i=1;i<=1000;i++)
    {
        P=1LL*P*p[poz];
        if(P>INF||p<0) break;
        back(poz+1,P);
    }
}
bool ap(long long n)
{
    int lin=Lin(n);
    for(it=v[lin].begin();it!=v[lin].end();it++)
        if(*it==n) return 1;
    return 0;
}
int main()
{
freopen("dtcsu.out","w",stdout);
for(i=1;i<=276997;i++)
    f>>sir;
INF=1000000000000000000;
p[1]=3;p[2]=5;p[3]=7;p[4]=11;
back(1,1);
f>>T;f.get();
while(T)
{
    T--;
    cit(V);
    if(V&(-V)) V=V/(V&(-V));
    sol+=ap(V);
}
printf("%d\n",sol);
return 0;
}