Pagini recente » Cod sursa (job #1612974) | Monitorul de evaluare | Cod sursa (job #725514) | Istoria paginii runda/ccex-2013-clasa-a-9-a/clasament | Cod sursa (job #2926468)
#include <iostream>
#include <fstream>
#include <bitset>
#include <vector>
using namespace std;
ifstream f("fractii.in");
ofstream g("fractii.out");
typedef long long LL;
vector<int> era;
int n;
void ciur(vector<int>& eratostene, int n){
char ciurul[n+1];
for(int i = 1; i <=n; i++) ciurul[i] = 0;
for(int i = 2; i <= n; i++)
if( !ciurul[i] ){
eratostene.push_back(i);
for(int j = i * i; j <= n; j += i )
ciurul[j] = '1';
}
}
inline LL putere(int p, int e){
LL rez = 1;
while(e>1)
rez*=p, e--;
return rez;
}
LL totient(int nr){
vector<int> puteri;
LL totientul = 1;
int i = 0, exponent;
while(nr > 1){
exponent = 0;
if(nr % era[i] == 0){
while(nr % era[i] == 0){
exponent++;
nr /= era[i];
}
}
puteri.push_back(exponent);
i++;
}
for(int cnt = 0; cnt < i; cnt++)
if( putere[ i ] )
totientul *= putere(era[cnt], puteri[cnt]) * (era[cnt] - 1);
return totientul;
}
int main()
{
f >> n;
ciur(era, n);
long long rez = 1;
for(int i = 2; i < n; i++)
rez += 2*totient(i);
///cout<<"merge totientul";
g << rez;
f.close(); g.close();
return 0;
}