素因数分解 
概要 
正整数 
計算量 
Snippet 
C++ 
cpp
std::map<long long, int> prime_factor(long long n) {
  std::map<long long, int> res;
  for (long long x = 2; x * x <= n; x++) {
    while (n % x == 0) {
      ++res[x];
      n /= x;
    }
  }
  if (n != 1) {
    res[n] = 1;
  }
  return res;
}Python 
python
def prime_factor(n):
    res, x = {}, 2
    while x * x <= n:
        while n % x == 0:
            res[x] = res.get(x, 0) + 1
            n //= x
        x += 1
    if n != 1:
        res[n] = 1
    return res解説 
整数を2から順番に小さい方から見ていき, 
整数を小さい方から貪欲に 
また, 割り算を試行する正整数 
割り算の回数が 
検証 
参考文献 
- プログラミングコンテストチャレンジブック