ACM训练联盟周赛 G. Teemo's convex polygon

  •  65536K
 

Teemo is very interested in convex polygon. There is a convex n-sides polygon, and Teemo connect every two points as diagonal lines, and he want to kown how many segments which be divided into intersections. Teemo ensure that any three diagonals do not intersect at a point.

As the result may be very large, please output the result mod 1000000007.

Input Format

The input contains several test cases, and the first line is a positive integer T indicating the number of test cases which is up to 100.

For each test case, the first line contains an integer n(3<=n<=10^18).

Output Format

For each test case, output a line containing an integer that indicates the answer.

样例输入

2
3
4

样例输出

0
4


 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 #include <cstdlib>
 5 #include <cstring>
 6 #include <string>
 7 #include <deque>
 8 #include <map>
 9 #include <vector>
10 #include <stack>
11 using namespace std;
12 #define  ll long long 
13 #define  N   29
14 #define  M 1000000000
15 #define  gep(i,a,b)  for(int  i=a;i<=b;i++)
16 #define  gepp(i,a,b) for(int  i=a;i>=b;i--)
17 #define  gep1(i,a,b)  for(ll i=a;i<=b;i++)
18 #define  gepp1(i,a,b) for(ll i=a;i>=b;i--)    
19 #define  mem(a,b)  memset(a,b,sizeof(a))
20 #define  ph  push_back
21 #define  mod  1000000007
22 void  egcd(ll a,ll b,ll &x,ll &y)
23 {
24     ll d=a;
25     if(!b) {
26         x=1;y=0;
27         return ;
28     }
29     else{
30         egcd(b,a%b,y,x);
31         y-=(a/b)*x;
32     }
33 }
34 ll inv(int n){
35     ll x,y;
36     egcd(n,mod,x,y);
37     return (x%mod+mod)%mod;
38 }
39 int t;
40 ll n;
41 /*
42 //任意三个无交点
43 n*(n-3) : 凸多边形的每个顶点与其他的点连接形成的线段数目
44 4*C(n,4) : 4个点形成形内1顶点,而1个点出现4个分割的线段
45 都出现了两次
(C(n,4)*4+n*(n-3))/2
46 / 47 int main() 48 { 49 scanf("%d",&t); 50 while(t--) 51 { 52 scanf("%lld",&n); 53 n%=mod;//避免溢出 54 ll ans=n*(n-3)%mod*(8+n*n%mod-3*n%mod+mod)%mod*inv(12)%mod; 55 printf("%lld\n",ans); 56 } 57 return 0; 58 }

 

posted on 2018-08-21 17:44  cltt  阅读(189)  评论(0)    收藏  举报

导航