# Sqare and sum difference

Dev Skill archived problems can be discussed here.

### Sqare and sum difference

whats problem in my code? why it doesnt get accepted ?

Code: Select all
`#include <stdio.h>long long calculate(int);int main() {        int test;        scanf("%d",&test);    if (test>0&&test<=10000) {        long long answer[test];                for (int i = 0; i<test; i++) {                        int val;            scanf("%d",&val);                        if (val>0&&val<=10000) {                                answer[i] = calculate(val);            }        }        for (int i = 0; i<test; i++) {            printf("%lld\n",answer[i]);        }    }    return 0;}long long calculate(int n){            long long sum1 = (n*(n+1)*(2*n+1))/6;        long long sum2 = (n*(2+(n-1)))/2;        long long diff = sum2*sum2 - sum1;        return diff;}`

Posts: 28
Joined: Sat Aug 06, 2016 11:02 pm

### Re: Sqare and sum difference

Your output do not match in 50% cases. the other 50% it does match. So please check your code properly. It looks like you are having trouble with big cases where the result is big. For smaller results, all seems OK. make sure you are not having overflow.

Posts: 118
Joined: Tue Feb 02, 2016 10:24 pm

### Re: Sqare and sum difference

All the input is correct but it shows W/A. Why??!

Posts: 1
Joined: Wed Nov 16, 2016 12:47 am

### Re: Sqare and sum difference

Looks like you got Accepted. Congratulation!