Pagini recente » Cod sursa (job #255889) | Cod sursa (job #690229) | Cod sursa (job #1178609) | Cod sursa (job #960888) | Cod sursa (job #1641237)
#include <fstream>
#include <iostream>
using namespace std;
int gcd( int a, int b ) {
int t;
if ( a < 0 )
a = -a;
if ( ! b )
return a;
if ( b < 0 )
b = -b;
if ( ! a )
return b;
t = 0;
while ( ! ( ( a | b ) & 1 ) ) {
a >>= 1;
b >>= 1;
++t;
}
while ( ! ( a & 1 ) )
a >>= 1;
while ( ! ( b & 1 ) )
b >>= 1;
while ( a != b ) {
if ( a > b ) {
a -= b;
do {
a >>= 1;
} while ( ! ( a & 1 ) );
}
else {
b -= a;
do {
b >>= 1;
} while ( ! ( b & 1 ) );
}
}
return a << t;
}
int main(){
long int n,s=0;
ifstream fin ("fractii.in");
ofstream fout ("fractii.out");
fin>>n;
for (long int i=1;i<=n;i++){
for(long int j=1;j<=n;j++){
int r = gcd(i,j);
if (r==1)
s++;
// cout<<"("<<i<<","<<j<<") "<<"r="<<r<<"\n";
}
}
fout<<s;
}