zoukankan      html  css  js  c++  java
  • POJ

    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 }
  • 相关阅读:
    Hexo个人博客主题配置
    Hexo+Github/Gitee 搭建个人博客
    TCP/IP协议架构介绍(四):应用层
    TCP/IP协议架构介绍(三):传输层
    TCP/IP协议架构介绍(一):网络接口层
    Linux Bash编程
    TCP/IP协议架构介绍(二):网络层
    charles SSL证书安装
    Linux常用命令:性能命令
    简繁转换
  • 原文地址:https://www.cnblogs.com/npugen/p/10870686.html
Copyright © 2011-2022 走看看