Pagini recente » Cod sursa (job #2525597) | Cod sursa (job #2540692) | Cod sursa (job #327783) | Cod sursa (job #1042013) | Cod sursa (job #508904)
Cod sursa(job #508904)
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <math.h>
#include <map>
using namespace std;
int totient(int n) {
map<int, int> mp;
int m = n;
int max = sqrt(n) + 1;
int i = 2;
while (true) {
if (i > m || i > max)
break;
if (m % i == 0) {
if (!mp[i]) {
mp[i] = 1;
} else {
mp[i]++;
}
m /= i;
continue;
}
i++;
}
if (m != 1)
if (!mp[m])
mp[m] = 1;
else
mp[m]++;
map<int, int>::iterator it;
long long a = 1, b = 1;
for (it = mp.begin(); it != mp.end(); it++) {
a *= ((*it).first - 1);
b *= ((*it).first);
// cout << (*it).first << ",";
}
return (n * a) / b;
}
int main() {
ifstream in("fractii.in");
ofstream out("fractii.out");
int n;
in >> n;
int t = 1;
for (int i = 2; i <= n; i++) {
int tot = totient(i);
t += tot*2;
// cout << "\n" << i << "=" << tot << endl;
}
cout << t;
out << t;
return 0;
}