Skip to content

Instantly share code, notes, and snippets.

Created June 9, 2012 07:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/2899967 to your computer and use it in GitHub Desktop.
Save anonymous/2899967 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <unordered_map>
#include <iostream>
using namespace std;
#define N 1000000
int phi (int n) {
int result = n;
for (int i=2; i*i<=n; ++i)
if (n % i == 0) {
while (n % i == 0)
n /= i;
result -= result / i;
}
if (n > 1)
result -= result / n;
return result;
}
//алгоритм "решето Эратосфена"
unsigned int a[N];
int main(){
//заполним все ячейки числами по порядку: 0,1,2,3...
int z;
long long q = 0;
for (int i = 2; i <= N; ++i)
{
q += phi(i);
}
cout << endl << q << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment