Cod sursa(job #1030289)

Utilizator IoannaPandele Ioana Ioanna Data 15 noiembrie 2013 16:08:05
Problema Dtcsu Scor 20
Compilator cpp Status done
Runda FMI No Stress 4 Marime 0.95 kb
#include <cstdio>
#include <cstring>

using namespace std;

int q;
long long n;
int nr;
char s[100];
int d[] = {2,3,5,7,11};

FILE *f = fopen("dtcsu.in","r");
FILE *g = fopen("dtcsu.out","w");


void read() {
    for (int i = 1; i <=  276997 ;i++)
        fgets(s,99,f);
    fgets(s,99,f);
    q = 0;
    int lim = strlen(s);
    if (s[lim-1] == '\n') lim--;
    for (int j = 0; j < lim; j++) {
       q = q*10 + s[j] - '0';
    }
    }

void rez() {
    for (int i=1;i <= q; i++) {
        fgets(s,99,f);

        int lim = strlen(s);
        if (s[lim-1] == '\n') lim--;
        n = 0;
        for (int j = 0; j < lim; j++) {
            n = n*10 + s[j] - '0';
        }
        for (int j = 0; j < 5 && n > 1; j++)
        {
            while (n%d[j] == 0) {
                n/=d[j];
            }
        }
        if (n==1) nr++;
    }
    fprintf(g,"%d",nr);
}

int main()
{

    read();
    rez();
    return 0;
}