Cod sursa(job #206427)

Utilizator DanyDanIrimia Daniel Ionut DanyDan Data 6 septembrie 2008 17:11:38
Problema Fractii Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.48 kb
#include <fstream.h>
int main ()
{
    ifstream f ("fractii.in");
    ofstream g ("fractii.out");
    long int N,P,Q,a,b,p=0;
    f>>N;
    for (P=1;P<=N-1;P++)
         for (Q=P+1;Q<=N;Q++)
             {a=P; b=Q;
              if (a%2!=0||b%2!=0)
                  {while (a!=b)
                          if (a>b) a=a-b;
                          else b=b-a;
                   if (a==1&&b==1) p++;}}
    g<<p*2+1;
    f.close();
    g.close();
    return 0;
}