Cod sursa(job #1030055)

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

using namespace std;

int q;
int 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);
    fscanf(f,"%d\n",&q);
}

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;
}