Cod sursa(job #1249399)

Utilizator costty94Duica Costinel costty94 Data 26 octombrie 2014 22:43:01
Problema Sum Scor 35
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.95 kb
/*#include <stdio.h>
#include <stdlib.h>

char v[1000111];
int n, x, i, y, s, j;

int main()
{
	freopen("sum.in", "r", stdin);
	freopen("sum.out", "w", stdout);

	scanf("%d", &n);

	for(i = 0; i < n; i++)
	{
		s = 1;
		scanf("%d", &x);
		for(y = 2; y <= 2*x; y++)
			v[y] = 1;
		for(y = 2; y <= 2*x; y++)
		{
			if(v[y] == 1)
			{
				for(j = y+y; j <= 2*x; j += y)
					v[j] = 0;
			}
		}
		for(y = 2; y <= 2*x; y++)
			if(v[y])
			{
				printf("%d ",y);
				s += y;
			}
		printf("%d\n", s);
	}
	return 0;
}*/

#include <iostream>
#include <fstream>
  using namespace std;
  int cmmdc(int a,int b)
  {  if (!b) return a;
  return cmmdc(b,a % b);
  }
 int main(void)
 {
    ifstream f("sum.in");
    ofstream g("sum.out");
   int n,x,y,i,j;
   f>>n;
   for(i=1;i<=n;i++)
   {   f>>x;
    y=0;
     for(j=1;j<=2*x;j++)
     {  if (cmmdc(x,j)==1) y=y+j;}
     g<<y<<"\n";
     }
     f.close();
   return 0;
   }