其他分享
首页 > 其他分享> > 核桃的数量

核桃的数量

作者:互联网

再将unordered_map改成map,把auto遍历改成迭代器遍历后,通过。

#include<iostream>
#include<map>

using namespace std;

int a, b, c;
map<int, int> primes;

void get(int x){
    for(int i = 2; i <= x / i; i ++){
        if(x % i == 0){
            int cnt = 0;
            while(x % i == 0) x /= i, cnt ++;
            primes[i] = max(primes[i], cnt);
        }
    }
    primes[x] = max(primes[x], 1);
}

int main(){
    cin >> a >> b >> c;
    
    get(a), get(b), get(c);
    
    int res = 1;
    
    map<int, int> :: iterator it = primes.begin();
    
    while(it != primes.end()){
        int cnt = (*it).second;
        while(cnt --) res *= (*it).first;
        it ++;
    }
    
    cout << res << endl;
    
    return 0;
}

标签:map,cnt,get,int,核桃,res,primes,数量
来源: https://www.cnblogs.com/tomori/p/13763623.html