Cod sursa(job #3265384)

Utilizator thinkphpAdrian Statescu thinkphp Data 29 decembrie 2024 20:57:35
Problema Fractii Scor 30
Compilator c-64 Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <stdio.h>
#define FIN "fractii.in"
#define FOUT "fractii.out"

void computePHI(int n, int *ptr) {
     int phi[n+1];
     int sum = 0;
     for(int i = 1; i <= n; ++i) phi[i] = i;
     for(int i = 2; i <= n; ++i) {
         //daca este numar prim
         if(phi[i]==i) {
            for(int j = i; j <= n; j+=i) {
                phi[j] = phi[j] / i * (i - 1);
            }
         }
         sum+=phi[i];
     }
     *ptr=(sum<<1)+1;
}

int main(int argc, char const *argv[]) {
  int n, ans;
  freopen(FIN, "r", stdin);
  freopen(FOUT, "w", stdout);
  scanf("%d",&n);
  computePHI(n,&ans);
  printf("%d",ans);

  return 0;
}