SPOJ - TRICOUNT
Problem Code : TRICOUNT Problem : Counting Triangles Platform : SPOJ Language : C Link : SPOJ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 //submitted //http://www.spoj.com/problems/TRICOUNT/ #include<stdio.h> int main () { int t; scanf( "%d" , & t); while (t -- ) { long long unsigned num,sum; scanf( "%llu" , & num); if (num % 2 == 0 ) sum = (num * (num + 2 ) * (( 2 * num) + 1 )) / 8 ; else sum = ((num * (num + 2 ) * (( 2 * num) + 1 )) - 1 ) / 8 ; printf( "%llu \n " ,sum); } return 0 ; }