POJ - 3910 - GCD Determinant(数论——GCD矩阵)

Time Limit: 1000 mSec

Problem Description

We say that a set S = {x1, x2, ..., xn} is factor closed if for any xi ∈ S and any divisor d of xi we have d ∈ S. Let’s build a GCD matrix (S) = (sij), where sij = GCD(xi, xj) – the greatest common divisor of xi and xj. Given the factor closed set S, find the value of the determinant:

Input

The input file contains several test cases. Each test case starts with an integer n (0 < n < 1000), that stands for the cardinality of S. The next line contains the numbers of S: x1, x2, ..., xn. It is known that each xi is an integer, 0 < xi < 2*10 9. The input data set is correct and ends with an end of file.

Output

For each test case find and print the value Dn mod 1000000007.

Sample Input

2
1 2
3
1 3 9
4
1 2 3 6

Sample Output

1
12
4

 

题解:这种结论题真是顶不住,记录下来当作积累吧,题目是在UVALive上交的,POJ的编译器实在有点老。。。

附上大佬的链接,有gcd矩阵的相关结论:

https://zhuanlan.zhihu.com/p/53447466

 

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 #define REP(i, n) for (int i = 1; i <= (n); i++)
 6 #define sqr(x) ((x) * (x))
 7 
 8 const int maxn = 1000 + 10;
 9 const int maxm = 200000 + 10;
10 const int maxs = 8;
11 
12 typedef long long LL;
13 typedef pair<int, int> pii;
14 typedef pair<double, double> pdd;
15 
16 const LL unit = 1LL;
17 const int INF = 0x3f3f3f3f;
18 const LL Inf = 0x3f3f3f3f3f3f3f3f;
19 const double eps = 1e-14;
20 const double inf = 1e15;
21 const double pi = acos(-1.0);
22 const LL mod = 1000000007;
23 
24 LL get_phi(LL n)
25 {
26     LL ans = n;
27     LL m = sqrt(n + 0.5);
28     for(LL i = 2; i <= m; i++)
29     {
30         if(n % i == 0)
31         {
32             while(n % i == 0)
33             {
34                 n  /= i;
35             }
36             ans = ans * (i - 1) / i;
37         }
38         if(n == 1)
39             break;
40     }
41     if(n > 1)
42         ans = ans * (n - 1) / n;
43     return ans;
44 }
45 
46 int n;
47 LL x;
48 
49 int main()
50 {
51     ios::sync_with_stdio(false);
52     cin.tie(0);
53     //freopen("input.txt", "r", stdin);
54     //freopen("output.txt", "w", stdout);
55     while(cin >> n)
56     {
57         LL ans = 1;
58         for(int i = 0; i < n; i++)
59         {
60             cin >> x;
61             ans *= get_phi(x);
62             ans %= mod;
63         }
64         cout << ans << endl;
65     }
66     return 0;
67 }

 

posted on 2019-05-15 17:06  随缘&不屈  阅读(233)  评论(0编辑  收藏  举报

导航