Cod sursa(job #2197551)

Utilizator YusyBossFares Yusuf YusyBoss Data 22 aprilie 2018 14:38:04
Problema Mins Scor 0
Compilator c Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <stdio.h>

char ciur[1000006];
int cnt(int x, int c, int d) {
  return ((c - 1) / x) * ((d - 1) / x);
}

int main() {
  FILE *fin, *fout;
  fin = fopen("mins.in", "r");
  fout = fopen("mins.out", "w");
  int c, d, i, j, sol;
  fscanf(fin, "%d%d", &c, &d);
  sol = 0;
  ciur[0] = ciur[1] = 1;
  for (i = 2; i <= 1000000; i++) {
    if (ciur[i] == 0) {
      for (j = 2 * i; j <= 1000000; j += i)
        ciur[j] = 1;
      sol += cnt(i, c, d);
    }
    else
      sol -= cnt(i, c, d);
  }
  fprintf(fout, "%d", (c - 1) * (d - 1) - sol);
  return 0;
}