Spoj problem SUM1

SUM1

#include<stdio.h>
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        long long n;
        scanf("%lld",&n);

        long long a,b,c;

        if(n%3)     a=n/3;
        else
        a=(n-1)/3;

        if(n%5)     b=n/5;
        else
        b=(n-1)/5;

        if(n%15)    c=n/15;
        else
        c=(n-1)/15;

        a=(3*a*(a+1))/2;
        b=(5*b*(b+1))/2;
        c=(15*c*(c+1))/2;

        printf("%lld\n",(a+b)-c);
    }

    return 0;
}

No comments:

Post a Comment