Cod sursa(job #1282253)

Utilizator alex136Alexandru Calin alex136 Data 4 decembrie 2014 00:23:23
Problema Fractii Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <fstream>
#include <iostream>

inline bool coprime(int a,int b){
    int q;
    if(a==1||b==1) return true;
    if(a==b) return false;
    if(b>a){q=a;a=b;b=q;}
    while(b){
        q=a%b;
        a=b;
        b=q;
    }
    return a==1;
}

int main(){
    int n,t=0,k,p;

    std::ifstream f("fractii.in");
    f>>n;
    f.close();

    for(k=1;k<=n;k++) for(p=k+1;p<=n;p++){
        if(coprime(k,p)) t+=2;
 //       std::cout<<coprime(k,p)+0<<' '<<k<<' '<<p<<'\n';
    }

    std::ofstream g("fractii.out");
    g<<t+1<<'\n';
    std::cout<<t+1<<'\n';
    g.close();
    return 0;
}