Cod sursa(job #1031344)

Utilizator tudorv96Tudor Varan tudorv96 Data 15 noiembrie 2013 17:45:42
Problema Dtcsu Scor 0
Compilator cpp Status done
Runda FMI No Stress 4 Marime 1.13 kb
#include <fstream>
#include <iostream>
using namespace std;

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

char P[1 << 19], *now;
int n, sol, prim[] = {2, 3, 5, 7, 11};

typedef unsigned long long ULL;

void parse () {
    if (!(*now)) {
        fin.get (P, (1 << 19) - 1, '\0');
        now = P;
    }
}

ULL get () {
    ULL sol = 0;
    while ((*now < '0' || *now > '9') && *now != '-') {
        now++;
        parse();
    }
    while (*now >= '0' && *now <= '9') {
        sol = sol * 10 + *now - '0';
        now++;
        parse();
    }
    return sol;
}

int main() {
    now = P;
    for (int i = 0; i < 276997; ++i)
        ULL x = get();
    n = get();
    for (int i = 0; i < n; ++i) {
        ULL x = get();
        if (x % 13 == 0 || x % 17 == 0 || x % 19 == 0 || x % 23 == 0 || x % 29 == 0 || x % 31 == 0)
            continue;
        for (int i = 0; x != 1 && i < 5; ++i) {
            ULL p = prim[i];
            if (x % p)
                continue;
            while (!(x % p))
                x /= p;
        }
        if (x == 1)
            sol++;
    }
    fout << sol;
}