Cod sursa(job #181219)

Utilizator firewizardLucian Dobre firewizard Data 18 aprilie 2008 01:57:28
Problema Sum Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.01 kb
#include <stdio.h>
#include <math.h>
#define INF 100000
char v[100000];
long n,x,i,j,nr,c,sq/*,p[10000]*/;
long long s,ttnt;
int p[]={0,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,
89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,
197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,
313,317,321,323,325,327,329,331,333,335,337,339,341,343,345,347,349,351,353,355,
357,359,361,363,365,367,369,371,373,375,377,379,381,383,385,387,389,391,393,395,
397,399,401,403,405,407,409,411,413,415,417,419,421,423,425,427,429,431,433,435,
437,439,441,443,445,447,449,451,453,455,457,459,461,463,465,467,469,471,473,475,
477,479,481,483,485,487,489,491,493,495,497,499,501,503,505,507,509,511,513,515,
517,519,521,523,525,527,529,531,533,535,537,539,541,543,545,547,549,551,553,555,
557,559,561,563,565,567,569,571,573,575,577,579,581,583,585,587,589,591,593,595,
597,599,601,603,605,607,609,611,613,615,617,619,621,623,625,627,629,631,633,635,
637,639,641,643,645,647,649,651,653,655,657,659,661,663,665,667,669,671,673,675,
677,679,681,683,685,687,689,691,693,695,697,699,701,703,705,707,709,711,713,715,
717,719,721,723,725,727,729,731,733,735,737,739,741,743,745,747,749,751,753,755,
757,759,761,763,765,767,769,771,773,775,777,779,781,783,785,787,789,791,793,795,
797,799,801,803,805,807,809,811,813,815,817,819,821,823,825,827,829};
int main()
{
    freopen("sum.in","r",stdin);
    freopen("sum.out","w",stdout);
    /*c=1;
    p[1]=2;
    for(i=3;i<=INF;i=i+2)      
    if(!v[i]) {p[++c]=i;
    for(j=3*i;j<=INF;j=j+2*i)v[j]=1;}*/
    scanf("%ld\n",&n);
    for(;n;n--)
    {
        scanf("%ld",&x);
        j=1;
        ttnt=x;nr=x; 
        while (nr>1){       
              if (nr%p[j]==0){
                 while(nr%p[j]==0)nr/=p[j];
                 ttnt=ttnt*(p[j]-1)/p[j];
                 }
              j++;
              }
        s=2*ttnt*x;
        printf("%ld\n",s);
        ttnt=0;s=0;
    }
    return 0;
}