Cod sursa(job #195581)

Utilizator soriynSorin Rita soriyn Data 19 iunie 2008 19:56:05
Problema Sum Scor 45
Compilator c Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <stdio.h>
#include <stdlib.h>


int cmmdc(int a,int b)
{
    int a1,b1,rest;
      a1=a;b1=b;

      while ((rest=a1%b1)!=0)

       {            a1=b1;

                    b1=rest;

       };

       
    return b1;
    
}            
int main()
{   
    int x,k,n,suma=0,p;
    FILE *i;
    FILE *o;
    i=fopen("sum.in","r");
    o=fopen("sum.out","w");
fscanf(i,"%d\n",&n);
for(k=1;k<=n;k++)
{   
    suma=0;             
   fscanf(i,"%d\n",&x);  
   if(x==1)suma=0;
    for(p=1;p<=2*x;p++)
   {
       if(cmmdc(p,x)==1)
       suma+=p;
       
       }
fprintf(o,"%d\n",suma);       
}  


  return 0;
}