Pagini recente » Cod sursa (job #610358) | Cod sursa (job #2036497) | Cod sursa (job #544152) | Cod sursa (job #2946322) | Cod sursa (job #3290623)
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <fstream>
using namespace std;
int cmmdc(int a, int b) {
while (b != 0) {
int r = a % b;
a = b;
b = r;
}
return a;
}
int solve(int n) {
int result = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (cmmdc(i, j) == 1) {
result++;
}
}
}
return result;
}
int main()
{
bool test = false;
if (test == true) {
if (solve(3) != 7) cout << "wrong answer for 3";
if (solve(4) != 11) cout << "wrong answer for 4";
if (solve(5) != 19) cout << "wrong answer for 5";
if (solve(10) != 63) cout << "wrong answer for 10";
} else {
ifstream in("fractii.in");
ofstream out("fractii.out");
int n;
in >> n;
out << solve(n);
in.close();
out.close();
}
return 0;
}