Pagini recente » Cod sursa (job #2704994) | Cod sursa (job #341407) | Cod sursa (job #598242) | Cod sursa (job #2365901) | Cod sursa (job #3233451)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
const int MAX_N = 1000000;
vector<int> compute_totient(int max_n) {
vector<int> totient(max_n + 1);
for (int i = 1; i <= max_n; ++i) {
totient[i] = i;
}
for (int i = 2; i <= max_n; ++i) {
if (totient[i] == i) { // i este prim
for (int j = i; j <= max_n; j += i) {
totient[j] = (totient[j] / i) * (i - 1);
}
}
}
return totient;
}
int main() {
ifstream inFile("fractii.in");
ofstream outFile("fractii.out");
int N;
inFile >> N;
vector<int> totient = compute_totient(N);
int count = 0;
for (int i = 1; i <= N; ++i) {
count += totient[i];
}
outFile << count << endl;
inFile.close();
outFile.close();
return 0;
}