Cod sursa(job #1249518)

Utilizator costty94Duica Costinel costty94 Data 27 octombrie 2014 08:26:06
Problema Sum Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <stdio.h>
#include <stdlib.h>

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

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 <= x; y++)
			if(x % y == 0)
				v[y] = 0;
		for(y = 2; y <= 2*x; y++)
		{
			if(v[y] == 0)
			{
				for(j = y+y; j <= 2*x; j += y)
					v[j] = 0;
			}
			else
				s += y;
		}
		printf("%lld\n", s);
	}
	return 0;
}