Cod sursa(job #2003430)

Utilizator pepsiM4A1Ozturk Arif pepsiM4A1 Data 22 iulie 2017 21:26:04
Problema Dtcsu Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <cstdio>
#include <unordered_set>
#define LL long long
using namespace std;
unordered_set<LL>ap;
const int DIM=50000;
int poz=DIM-1;
char buff[DIM];
void citeste(LL &nr)
{
    nr=0;
    while(!('0'<=buff[poz]&&buff[poz]<='9'))
    {
        if(++poz==DIM) fread(buff,1,DIM,stdin),poz=0;
    }
    while('0'<=buff[poz]&&buff[poz]<='9')
    {
        nr=nr*10 + buff[poz]-'0';
        if(++poz==DIM) fread(buff,1,DIM,stdin),poz=0;
    }
}
int main()
{
    freopen ("dtcsu.in","r",stdin);
    freopen ("dtcsu.out","w",stdout);
    LL val;
    for(int i=1;i<=276997;i++)
    {
        citeste(val);
        while(val%2==0) val/=2;
        while(val%3==0) val/=3;
        ap.insert(val);
    }
    LL q;
    citeste(q);
    int ct=0;
    for(;q>0;--q)
    {
        citeste(val);
        while(val%2==0) val/=2;
        while(val%3==0) val/=3;
        if(ap.find(val)!=ap.end()) ++ct;
    }
    printf("%d\n",ct);
}