cpp-library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub 9tc/cpp-library

:x: 素因数分解
(math/prime-factorize.hpp)

Verified with

Code

#pragma once
template <class T>
map<T, int> primeFactorize(T n) {
  map<T, int> res;
  for(T i = 2; i * i <= n; ++i){
    while(n % i == 0){
      ++res[i];
      n /= i;
    }
  }
  if(n != 1) res[n] = 1;
  return res;
}
#line 2 "math/prime-factorize.hpp"
template <class T>
map<T, int> primeFactorize(T n) {
  map<T, int> res;
  for(T i = 2; i * i <= n; ++i){
    while(n % i == 0){
      ++res[i];
      n /= i;
    }
  }
  if(n != 1) res[n] = 1;
  return res;
}
Back to top page