Pagini recente » Cod sursa (job #2824745) | Cod sursa (job #2953074) | Cod sursa (job #1799689) | Cod sursa (job #2076254) | Cod sursa (job #1282248)
#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=1;p<=n;p++){
if(coprime(k,p)) t++;
// std::cout<<coprime(k,p)+0<<' '<<k<<' '<<p<<'\n';
}
std::ofstream g("fractii.out");
g<<t<<'\n';
g.close();
return 0;
}