Cod sursa(job #2197092)

Utilizator vladth11Vlad Haivas vladth11 Data 21 aprilie 2018 10:03:31
Problema Sum Scor 45
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <fstream>
#define N 200002
using namespace std;
ifstream cin("sum.in");
ofstream cout("sum.out");
int e[N];
void calc_Euler( int n ) {
  for ( int i = 2; i <= n; i ++ )
    e[i] = i;
  for ( int i = 2; i <= n; i ++ )
    if ( e[i] == i )
      for ( int j = i; j <= n; j += i )
        e[j] = e[j] / i * ( i - 1 );
}
int main()
{
    int n,x,i,y,sum = 0,j,w;
    cin >> n;
    for(i = 0; i < n; i++)
    {
        cin >> x;
        calc_Euler(x);
        cout << x*e[x]*2 << "\n";
    }
    return 0;
}