首页 > 代码库 > SWJTU2017-6月月赛 G-A Easy Counting Problem[数论][乘法逆元]

SWJTU2017-6月月赛 G-A Easy Counting Problem[数论][乘法逆元]

传送门:http://www.swjtuoj.cn/problem/2397/


 

技术分享


题解:产生交点的条件为4个点构成四边形对角线产生交点,最大解当产生的交点位置完全不相同时存在。答案为$C_{\text{n}}^4$

计算组合数时需要使用乘法逆元

代码:

 1 #define _CRT_SECURE_NO_DEPRECATE
 2 #pragma comment(linker, "/STACK:102400000,102400000")
 3 #include<iostream>  
 4 #include<cstdio>  
 5 #include<fstream>  
 6 #include<iomanip>
 7 #include<algorithm>  
 8 #include<cmath>  
 9 #include<deque>  
10 #include<vector>  
11 #include<assert.h>
12 #include<bitset>
13 #include<queue>  
14 #include<string>  
15 #include<cstring>  
16 #include<map>  
17 #include<stack>  
18 #include<set>
19 #include<functional>
20 #define pii pair<int, int>
21 #define mod 1000000007
22 #define mp make_pair
23 #define pi acos(-1)
24 #define eps 0.00000001
25 #define mst(a,i) memset(a,i,sizeof(a))
26 #define all(n) n.begin(),n.end()
27 #define lson(x) ((x<<1))  
28 #define rson(x) ((x<<1)|1) 
29 #define inf 0x3f3f3f3f
30 typedef long long ll;
31 typedef unsigned long long ull;
32 using namespace std;
33 const int maxn = 1e4 + 5;
34 ll poww(ll m, int n)
35 {
36     ll ans = 1;
37     ll temp = m;
38     while (n)
39     {
40         if (n & 1)
41             ans *= temp;
42         temp *= temp;
43         ans %= mod;
44         temp %= mod;
45         n >>= 1;
46     }
47     return ans%mod;
48 }
49 
50 int main()
51 {
52     ios::sync_with_stdio(false);
53     cin.tie(0); cout.tie(0);
54     int T;
55     ll n;
56     cin >> T;
57     while (T--)
58     {
59         cin >> n;
60         ll temp = n;
61         for (ll i = 1; i <= 3; ++i)
62         {
63             ll tt = poww(i + 1, mod - 2);
64             temp = (temp*(n - i)) % mod;
65             temp = (temp*tt) % mod;
66         }
67         cout << temp << endl;
68     }
69     return 0;
70 }

 

SWJTU2017-6月月赛 G-A Easy Counting Problem[数论][乘法逆元]