1 条题解

  • 0
    @ 2025-10-10 19:52:16

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    
    /*
    思路:
    1、分别将a1、a2、a3...an的质因数,求出每个质数的次数 
    2、求(指数+1)相乘的乘积 
    */
    int n;
    //哈希表,存储所有的底数和指数
    unordered_map<int,int> primes; 
    const int MOD = 1e9 + 7;
    typedef long long LL;
     
    int main() {
    	cin>>n;
    	int x;
    	while(n--){
    		cin>>x;
    		int i = 2;
    		for(int i = 2;i <= x / i;i++){
    			while(x % i == 0){
    				x = x / i;
    				primes[i]++;//质因子i出现的次数+1 
    			}
    		}
    		
    		if(x > 1) primes[x]++;//说明x是一个比较大的质因数 
    	}
    	
    	LL res = 1,t,s;
    	unordered_map<int,int>::iterator it;
    	for(it = primes.begin();it != primes.end();it++){
    		t = 1;//t代表次方 
    		s = 0;
    		for(int j = 0;j <= it->second;j++){
    			s = (s + t) % MOD;//加上,防止溢出 
    			t = (t * it->first) % MOD; 
    		}
    		res = (res * s) % MOD;
    	}
    	cout<<res;
    	return 0;
    }
    
    
    • 1

    信息

    ID
    1057
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者