Pagini recente » Cod sursa (job #3288670) | Cod sursa (job #3269246) | Cod sursa (job #2854465) | Cod sursa (job #160200) | Cod sursa (job #3132346)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fractii.in");
ofstream fout("fractii.out");
const int MAX_N = 1000005;
int n;
int eulerIndicator[MAX_N];
long long answer;
void HandleInput() {
fin >> n;
}
void GenerateEulerIndicator() {
for (int i = 1; i <= n; i++) {
eulerIndicator[i] = i;
}
for (int i = 2; i <= n; i++) {
if (eulerIndicator[i] == i) {
for (int j = i; j <= n; j += i) {
eulerIndicator[j] = eulerIndicator[j] / i * (i - 1);
}
}
}
}
void ComputeAnswer() {
for (int i = 1; i <= n; i++) {
answer += eulerIndicator[i];
}
answer = answer * 2 - 1;
}
void HandleOutput() {
fout << answer << '\n';
}
int main() {
HandleInput();
GenerateEulerIndicator();
ComputeAnswer();
HandleOutput();
return 0;
}