约数常见问题

#include <iostream>
#include <unordered_map>

using namespace std;

int main(){
    unordered_map<int, int> hash;
    for(int i = 1; i <= 100; ++i){
        int t = i;
        int j = 2;
        for(j = 2; j <= i / j; ++j){
            while(t % j == 0){
                t /= j;
                hash[j] ++;
            }
        }
        if(t > 1) hash[t] ++;
        //cout << i << endl;
    }
    unsigned long long res = 1;
    for(auto i : hash){
        res = res * (i.second + 1);
    }
    cout << res;
    return 0;
}

#include <iostream>
#include <unordered_map>

using namespace std;
typedef long long LL;

const int mod = 1e9 + 7;

int main(){
    int n;
    cin >> n;
    unordered_map<int, int> hash;

    while(n --){
        int t;
        cin >> t;
        for(int i = 2; i <= t / i; ++i){
            while (t % i == 0){
                t /= i;
                hash[i] ++;
            }
        }
        if(t > 1) hash[t] ++;
    }
    LL res = 1;
    for(auto i : hash){
        LL a = i.first, b = i.second;
        LL t = 1;
        while( b -- ) t = (t * a + 1) % mod;
        res = res * t % mod; 
    }
    cout << res << endl;
    return 0;
}

//欧几里得算法求最大公约数

int gcd(int a, int b){
      return b ? gcd(b, a % b) : a;
}
posted @ 2020-11-17 23:08  Diaphanous  阅读(62)  评论(0)    收藏  举报