#include <map>
#include <iostream>
using namespace std;
map<int, int> prime_factor(int n){
map<int, int> res;
for(int i = 2; i * i <= n; ++i){
while(n % i == 0){
//往map中添加键值对
++res[i];
n /= i;
}
}
if(n != 1)
//如果n本身就是一个素数,则把n也添加中map中,值为1
res[n] = 1;
return res;
}
int main(){
map<int, int> ans = prime_factor(10);
//定义一个迭代器
map<int, int>::iterator it;
//访问map
for(it = ans.begin(); it != ans.end(); ++it)
cout << it -> first << " " << it -> second << endl;
//删除一组键值对
ans.erase(2);
for(it = ans.begin(); it != ans.end(); ++it)
cout << it -> first << " " << it -> second << endl;
return 0;
}