Cod sursa(job #2060293)

Utilizator stahlhelmVirtejaru Mihai stahlhelm Data 8 noiembrie 2017 02:44:01
Problema Fractii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("fractii.in");
ofstream c("fractii.out");
int divizor(int x,int y)
{int r;
r=x%y;
while(r!=0)
   {
   x=y;
   y=r;
   r=x%y;
   }
if(y==1)
 return 0;
}
int main()
{ int N,s=0,p=0;
unsigned long long phi[100000];
f>>N;
  for (int i = 1; i <= N; ++i)
    phi[i] = i-1;
for (int i = 2; i <= N; ++i)
   for (int j = 2*i; j <= N; j += i)
        phi[j] -= phi[i];

   for(int j=2;j<=N;j++)
           p+=phi[j];

    for(int i=2;i<=N-1;i++)
    {
        for(int j=i+1;j<=N;j++)
          if(divizor(i,j)==0)
             s++;

    }

        c<<p+N+s;

return 0;
}