N points on the circle, and the two adjacent points are connected (Note: N and 1 are adjacent). Then all the points (I, I + 2) are connected, how many triangles can be formed?
Train of Thought: Find the rule
N = 3, CNT = 1;
N = 4, CNT = 8;
N = 5 CNT = 35 (5*2 + 5*2 + 5 + 5 + 5 );
N = 6 CNT = 32 (6*2 + 6*2 + 6 + 2 );
N = 7, CNT = 35 (7*2 + 7*2 + 7 );
N = 8, CNT = 40 (8*2 + 8*2 + 8)
N> 6; CNT = 5 * N;
AC code:
1 #include<stdlib.h> 2 #include<stdio.h> 3 #include<string.h> 4 #define m 20121111 5 int main() 6 { 7 int t,n; 8 scanf("%d",&t); 9 int cas=1;10 while(t--)11 {12 int ans;13 scanf("%d",&n);14 if(n<3)15 ans = 0;16 else if(n == 3)17 ans = 1;18 else if(n == 4)19 ans = 8;20 else if(n == 5)21 ans = 35;22 else if(n == 6)23 ans = 32;24 else25 ans = 5*n;26 printf("Case #%d: %d\n",cas++,ans%m);27 }28 return 0;29 }
A very easy triangle counting game