Cod sursa(job #1566049)

Utilizator eu3neuomManghiuc Teodor-Florin eu3neuom Data 11 ianuarie 2016 19:24:25
Problema Dtcsu Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("dtcsu.in");
ofstream fout("dtcsu.out");

const int NMax = 276997;
const int Size = 20;
const int BMax = 1e5;
const int v[] = {2, 3, 5, 7, 11};

char S[Size];

int pos = BMax - 1;
char Buffer[BMax];
inline void Read(long long int &x){
    while(!isdigit(Buffer[pos])){
        if(++pos == BMax){
            fin.read(Buffer, BMax);
            pos = 0;
        }
    }
    x = 0;
    while(isdigit(Buffer[pos])){
        x = x * 10 + (Buffer[pos] - '0');
        if(++pos == BMax){
            fin.read(Buffer, BMax);
            pos = 0;
        }
    }
}

int main(){
    long long int q, ans, x;
    for(int i = 1; i <= NMax; i++) fin >> S;
    Read(q);
    ans = 0;
    while(q--){
        Read(x);
        for(int i = 0; i < 5; i++){
            while(x % v[i] == 0) x /= v[i];
        }
        if(x == 1) ans++;
    }
    fout << ans;
    return 0;
}