Cod sursa(job #2792136)

Utilizator Teodor94Teodor Plop Teodor94 Data 31 octombrie 2021 23:37:02
Problema Dtcsu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.66 kb
#include <stdio.h>
#include <ctype.h>

#define int64 long long
#define NO_NUMBERS 276997

FILE *fin, *fout;

#define BUF_SIZE 4096
char buf[BUF_SIZE];
int pos = BUF_SIZE;
inline char getChar() {
  if (pos == BUF_SIZE) {
    fread(buf, 1, BUF_SIZE, fin);
    pos = 0;
  }
  return buf[pos++];
}
inline int64 readInt64() {
  int64 result = 0;
  char c;
  do {
    c = getChar();
  } while (!isdigit(c));

  do {
    result = result * 10 + c - '0';
    c = getChar();
  } while (isdigit(c));

  return result;
}

int64 bases[5] = {2, 3, 5, 7, 11};
int64 noExponents[5] = {6, 6, 5, 5, 5};
int64 exponents[5][6] = {
  {1, 2, 4, 8, 16, 32}, //  2
  {1, 2, 4, 8, 16, 32}, //  3
  {1, 2, 4, 8, 16},     //  5
  {1, 2, 4, 8, 16},     //  7
  {1, 2, 4, 8, 16}      // 11
};
int64 powers[5][6];

void pregenPowers() {
  int i, j, k;

  for (i = 0; i < 5; ++i)
    for (j = 0; j < noExponents[i]; ++j) {
      powers[i][j] = 1;
      for (k = 0; k < exponents[i][j]; ++k)
        powers[i][j] *= bases[i];
    }
}

int64 removePowers(int64 x) {
  int i, j;

  for (i = 0; x > 1 && i < 5; ++i)
    for (j = noExponents[i] - 1; x > 1 && j >= 0; --j)
      if (x % powers[i][j] == 0)
        x /= powers[i][j];

  return x;
}

int main() {
  fin = fopen("dtcsu.in", "r");
  fout = fopen("dtcsu.out", "w");

  int i, q, counter;
  int64 x;

  for (i = 0; i < NO_NUMBERS; ++i)
    x = readInt64();

  pregenPowers();

  counter = 0;
  q = readInt64();
  while (q--) {
    x = readInt64();
    x = removePowers(x);

    counter += x == 1;
  }

  fprintf(fout, "%d\n", counter);

  fclose(fin);
  fclose(fout);
  return 0;
}