ACM (UVa) : 10302


Formulas: [x = 1 to n]

Σ x ^ 1 = n * (n + 1) / 2;

Σ x ^ 2 = n * (n + 1) * (2n + 1) / 6;

Σ x ^ 3 = (n ^ 2) * ((n + 1) ^ 2) / 4; [*** our required formula]

links : http://polysum.tripod.com/

Take input as double data type.
And the output would be long long data type.


#include "stdio.h"
#include "math.h"

int main ()
{
    double x;

    while (scanf ("%lf", &x) != EOF) {

        //long long res = pow ((x/2),2) * pow ((x+1),2);

		long long res = pow (x, 2) * pow (x + 1, 2) / 4;

        printf("%lld\n", res);
    }

    return 0;
}


Critical input:
1000
5000
10000
20000
30000
50000

Critical output:
250500250000
156312506250000
2500500025000000
40004000100000000
202513500225000000
1562562500625000000

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s