zoukankan      html  css  js  c++  java
  • 计数原理

     
    //cf 615D
    D. Multipliers
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Ayrat has number n, represented as it's prime factorization pi of size m, i.e. n = pp2·...·pm. Ayrat got secret information that that the product of all divisors of n taken modulo 109 + 7 is the password to the secret data base. Now he wants to calculate this value.

    Input

    The first line of the input contains a single integer m (1 ≤ m ≤ 200 000) — the number of primes in factorization of n.

    The second line contains m primes numbers pi (2 ≤ pi ≤ 200 000).

    Output

    Print one integer — the product of all divisors of n modulo 109 + 7.

    Examples
    input
    Copy
    2
    2 3
    output
    Copy
    36
    input
    Copy
    3
    2 3 2
    output
    Copy
    1728
    Note

    In the first sample n = 2·3 = 6. The divisors of 6 are 1, 2, 3 and 6, their product is equal to 1·2·3·6 = 36.

    In the second sample 2·3·2 = 12. The divisors of 12 are 1, 2, 3, 4, 6 and 12. 1·2·3·4·6·12 = 1728.

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <string>
     5 #include <algorithm>
     6 #include <utility>
     7 #include <vector>
     8 #include <map>
     9 #include <queue>
    10 #include <stack>
    11 #include <cstdlib>
    12 typedef long long ll;
    13 #define lowbit(x) (x&(-x))
    14 #define ls l,m,rt<<1
    15 #define rs m+1,r,rt<<1|1
    16 using namespace std;
    17 const int   mod= 1e9+7;
    18 const int N=2e5+9;
    19 int num[N],a[N];
    20 ll l[N],r[N];
    21 int n,x;
    22 ll poww(ll a,ll b,ll mod){
    23     ll ret=1%mod;
    24     while(b){
    25         if(b&1ll) ret=ret*a%mod;
    26         b>>=1;
    27         a=a*a%mod;
    28     }
    29     return  ret%mod;
    30 }
    31 int main()
    32 {
    33     scanf("%d",&n);
    34     int   top=0;
    35     for(int  i =0;i< n;i++){
    36         scanf("%d",&x);
    37         if(!num[x]) a[++top] =x;//共top个数
    38         num[x]++;
    39     }
    40     /*
    41     l[i]:1~i个因子的组合方案数
    42     r[i]:i~top个因子的组合方案数
    43     */
    44     l[0]=r[top+1]=1;//自己不存在,但可以和其他的因子组合
    45     for(int i=1;i<=top;i++){
    46         l[i]=l[i-1]*(1ll+num[a[i]])%(mod-1);
    47         /*
    48         第i个因子可以取或不取:
    49         不取 :就是l[i-1]
    50         取:l[i-1]*num[a[i]]
    51         */
    52     }
    53     for(int i=top;i>=1;i--){
    54         r[i]=r[i+1]*(1ll+num[a[i]])%(mod-1);
    55     }
    56     ll ans=1;
    57     for(int i=1;i<=top;i++){
    58         ll numm=num[a[i]];
    59         numm=(numm*(numm+1))/2%(mod-1);
    60         //1+2+3+……+numm
    61         //1个,2个....(a[i])分别和前后组合的结果拼接
    62         ll z =l[i-1]*r[i+1]%(mod-1);//前后的组合方案数
    63         numm=numm*z%(mod-1);//a[i]出现了numm次
    64         ans=ans*poww(a[i],numm,mod)%mod;
    65     }
    66     printf("%lld
    ",ans);
    67     return    0;
    68 }
  • 相关阅读:
    字节跳动--今日头条iOS客户端启动速度优化
    RSA加密
    几种浏览器
    Linux定时任务crontab无法执行
    Python报错ImportError: No Module Named Typing的解决
    微信小程序:A、B两个小程序相互跳转,出现点击A小程序底部导航栏菜单,第一次点击无法跳转B小程序,需要点击第二次才会触发跳转到B小程序
    c# core 生成随机图文验证码
    携程Apollo统一配置管理中心
    WPF程序中嵌入winForm窗体
    sqlserver 转 postgresql
  • 原文地址:https://www.cnblogs.com/tingtin/p/10063378.html
Copyright © 2011-2022 走看看