Codeforces 615D Multipliers(数学推公式)

escription

Ayrat has number n, represented as it's prime factorization pi of size m, i.e. n = p1·p2·...·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.

Sample Input

Input
2
2 3
Output
36
Input
3
2 3 2
Output
1728

Hint

In the first sample n = 2·3 = 6. The divisors of 6 are 123 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 12346 and 121·2·3·4·6·12 = 1728.


题意:题目很清楚,给你n个质因数,求他们的积的所有因子之积(包括1和本身)。

(看到题目很懵圈~想着要是知道所有因子该有多好~(那还做个P的题目))。


思路:(我也是看题解的,简单翻译一下吧.)

题目已给n个质因数,这个条件好好哦,如果不是,那还得自己求质因数~.我们设n个质因数之积为x,那么x的因子个数必定是由这n个质因数两两乘或者是一个数本身.直接给出公式:x=p1^a1*p2^a2*p3^a3*.......*pn^an,

那么设d(x)为x的因子个数:d(x)=(a1+1)*(a2+1)*(a3+1)*...*(an+1);

(这个公式可以这样理解:有a1个p1,那么可以选0个,1个,2个...a1个,所以有(a1+1)。)

x其中的一个因子m,那么也就有x/m这个因子的存在。那么就有d(x)/2对这样的因子,

所以设f(x)为最终答案,给出公式f(x)=x^(d(x)/2)

那么要是x是个完全平方数,d(x)不是个奇数吗?怎么办?要多乘一个sqrt(x).?

其实并不用。

因为x很大,d(x)/2也很大,我们并不能直接求取。

那么就要拆开取模,怎么拆啊?d(ab)=d(a)*d(b),f(ab)=f(a)^d(b)*f(b)^d(a)

所以对于一个x是完全平方数,就有公式f(p^k)=p^(k*(k+1)/2),可以直接得到,所以不用多乘sqrt(x)(将fx公式带入得)。

拆完x,那指数d(x)/2很大咋办?那么由费马小定理得:,所以指数只能对(mod-1)取模。(因为它处在指数位置,所以不能随便对mod直接取模)。

哭 真不容易~

附上AC代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include<stdio.h>
#include<math.h>
#include<string.h>
#define max(a,b) a>b?a:b
#include<map>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
long long quickpow(long long n,long long m)
{
    long long ans=1;
    while(m>0)
    {
        if(m&1)ans=ans*n%mod;
        m>>=1;
        n=n*n%mod;
    }
    return ans;
}
int main()
{
    int n,a,Max;
    while(~scanf("%d",&n))
    {
        map<ll ,ll >p;
        map<ll ,ll >::iterator it;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a);
            p[a]++;
        }
        long long d=1,ans=1,fp;
        for(it=p.begin(); it!=p.end(); it++)
        {
            fp=quickpow(it->first,(it->second+1)*it->second/2);
            ans=quickpow(ans,(it->second+1))*quickpow(fp,d)%mod;
            d=d*(it->second+1)%(mod-1);
        }
        printf("%I64d\n",ans);
    }
}



### Codeforces 1487D Problem Solution The problem described involves determining the maximum amount of a product that can be created from given quantities of ingredients under an idealized production process. For this specific case on Codeforces with problem number 1487D, while direct details about this exact question are not provided here, similar problems often involve resource allocation or limiting reagent type calculations. For instance, when faced with such constraints-based questions where multiple resources contribute to producing one unit of output but at different ratios, finding the bottleneck becomes crucial. In another context related to crafting items using various materials, it was determined that the formula `min(a[0],a[1],a[2]/2,a[3]/7,a[4]/4)` could represent how these limits interact[^1]. However, applying this directly without knowing specifics like what each array element represents in relation to the actual requirements for creating "philosophical stones" as mentioned would require adjustments based upon the precise conditions outlined within 1487D itself. To solve or discuss solutions effectively regarding Codeforces&#39; challenge numbered 1487D: - Carefully read through all aspects presented by the contest organizers. - Identify which ingredient or component acts as the primary constraint towards achieving full capacity utilization. - Implement logic reflecting those relationships accurately; typically involving loops, conditionals, and possibly dynamic programming depending on complexity level required beyond simple minimum value determination across adjusted inputs. ```cpp #include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; vector<long long> a(n); for(int i=0;i<n;++i){ cin>>a[i]; } // Assuming indices correspond appropriately per problem statement&#39;s ratio requirement cout << min({a[0], a[1], a[2]/2LL, a[3]/7LL, a[4]/4LL}) << endl; } ``` --related questions-- 1. How does identifying bottlenecks help optimize algorithms solving constrained optimization problems? 2. What strategies should contestants adopt when translating mathematical formulas into code during competitive coding events? 3. Can you explain why understanding input-output relations is critical before implementing any algorithmic approach? 4. In what ways do prefix-suffix-middle frameworks enhance model training efficiency outside of just tokenization improvements? 5. Why might adjusting sample proportions specifically benefit models designed for tasks requiring both strong linguistic comprehension alongside logical reasoning skills?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值