Cod sursa(job #181217)

Utilizator firewizardLucian Dobre firewizard Data 18 aprilie 2008 01:29:45
Problema Sum Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <stdio.h>
#include <math.h>
#define INF 100000
char v[100000];
long n,x,i,j,ttnt,s,nr,c,p[10000],sq;
int main()
{
    freopen("sum.in","r",stdin);
    freopen("sum.out","w",stdout);
    scanf("%ld\n",&n);
    for(;n;n--)
    {
        scanf("%ld",&x);
        //---------ciur
        c=1;
        p[1]=2;
        for(i=3;i<=x;i=i+2)      
        if(!v[i]) {p[++c]=i;
        for(j=3*i;j<=x;j=j+2*i)v[j]=1;} 
        //----------ciur
        ttnt=x;
       for(j=1;j<=c;j++)
       if(x%p[j]==0)ttnt=ttnt*(p[j]-1)/p[j];
        s=2*ttnt*x;
        printf("%ld\n",s);
        ttnt=0;s=0;
    }
    return 0;
}