Pagini recente » Cod sursa (job #1128891) | Cod sursa (job #3164080) | Cod sursa (job #2767931) | Cod sursa (job #1167514) | Cod sursa (job #1282253)
#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;
}