Pagini recente » Cod sursa (job #2259850) | Cod sursa (job #1088650) | Utilizatori inregistrati la Grigore Moisil 2009, clasa a 10a | Cod sursa (job #951311) | Cod sursa (job #139357)
Cod sursa(job #139357)
#include<iostream.h>
#include<stdio.h>
int main ()
{long int contor=0,P=2,Q,P2,Q2,N,div;
int truth=1,truth2=3;
freopen ("fractii.in", "rt" ,stdin);
freopen ("fractii.out","wt" ,stdout);
scanf ("%ld", &N);
if (N==1) printf ("%d",truth);
else if (N==2) printf ("%d",truth2);
else {for (contor=0;P<=N;P++)
{Q=2;
while (Q<P) {div=P2%Q2; Q2=Q; P2=P;
while (div!=0) {P2=Q2;
Q2=div;
div=P2%Q2;}
if (Q2==1) contor++;
Q++;}}
contor=contor*2+2*N-1;
printf ("%ld",contor);}
return 0;}