Cod sursa(job #1254640)

Utilizator costty94Duica Costinel costty94 Data 3 noiembrie 2014 09:07:39
Problema Sum Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <stdio.h>
#include <stdlib.h>
 
int 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;
}