Pagini recente » Cod sursa (job #517495) | Cod sursa (job #82099) | Cod sursa (job #499387) | Cod sursa (job #1265212) | Cod sursa (job #2864652)
#include<iostream>
#include<fstream>
using namespace std;
ifstream fin("fractii.in");
ofstream fout("fractii.out");
int cmmdc(int a, int b) {
int divizor = 2;
int s = 0, aux = 0;
if (a < b) {
aux = a;
a = b;
b = aux;
}
while (divizor <= b) {
if ((a % divizor == 0) && (b % divizor == 0)) {
s = divizor;
}
divizor++;
}
if (s == 0) {
return 1;
}
else {
return 0;
}
}
int fractii(int n) {
int i, j, s = 0;
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
if ((i != 1 && j != 1) && (cmmdc(i,j)==0)) {
s = s;
}
else {
s++;
}
}
}
return s;
}
int main() {
int n;
fin >> n;
if (n > 0) {
fout << fractii(n);
}
return 0;
}