Pagini recente » Cod sursa (job #783261) | Cod sursa (job #2665942) | Cod sursa (job #81960) | Cod sursa (job #954168) | Cod sursa (job #3233431)
#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 is a prime
for (int j = i; j <= max_n; j += i) {
totient[j] = totient[j] * (i - 1) / i;
}
}
}
return totient;
}
int main() {
ifstream inFile("fractii.in");
ofstream outFile("fractii.out");
int N;
inFile >> N;
vector<int> totient = compute_totient(MAX_N);
int count = 0;
for (int i = 1; i <= N; ++i) {
count += totient[i];
}
outFile << count << endl;
inFile.close();
outFile.close();
return 0;
}