Cod sursa(job #206429)

Utilizator DanyDanIrimia Daniel Ionut DanyDan Data 6 septembrie 2008 17:40:50
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;
    p=N-1;
    for (P=2;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-=b;
                          else b-=a;
                   if (a==1) p++;}}
    g<<p*2+1;
    f.close();
    g.close();
    return 0;
}