Cod sursa(job #1181843)
| Utilizator | Data | 3 mai 2014 22:48:23 | |
|---|---|---|---|
| Problema | Fractii | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.53 kb |
#include <fstream>
using namespace std;
ifstream f("fractii.in");
ofstream g("fractii.out");
//returns greatest common divisor between two numbers
int gcd (int a, int b)
{
int c;
while ( a != 0 )
{
c = a;
a = b % a;
b = c;
}
return b;
}
int main()
{ int n;
f>>n;
int i, j, count = 0;
for(i = 1; i <= n; i++)
{
for(j = 1; j <= n; ++j)
{
if(gcd(i, j) == 1)
++count;
}
}
g<<count;
return 0;
}
