Cod sursa(job #193439)

Utilizator carloneIoan-Carol Plangu carlone Data 4 iunie 2008 16:14:16
Problema Fractii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include"stdio.h"
#include"stdint.h"
#include <cstdlib>
long x;
long out;
struct nod
{
       int n;nod *next;
};nod *a,*b,*c;
int_fast32_t cmmdc(int_fast32_t x,int_fast32_t y)
{int b=0;
    while(x&&y)
    {
    switch(b)
    {
    case 0: x%=y;break;
    case 1: y%=x;break;
    }
    b=(b+1)%2;
    }
    if(x)return x;else return y;
}
int val(const int_fast32_t x,const int_fast32_t y)
{
     if(!x||!y)return 0;
     if(cmmdc(x,y)==1)return 1;
     return 0;
}
int main()
{
    freopen("fractii.out","w",stdout);
    //freopen("fractii.in","r",stdin);
    scanf("%ld",&x);
    for(int_fast32_t g=0;g<(x+1)*(x+1)-1;g++){out+=val(g%(x+1),(g+1)/(x+1));}
    printf("%ld",out);
    return 0;
}