Language: C++

#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);++i)
#define rep1(i, n) for(int i=1;i<=(int)(n);++i)
#define irep(i, a, n) for(int i=a;i<(int)(n);++i)
#define rrep(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define rrep1(i, n) for(int i=(int)(n);i>=1;--i)
#define allrep(V, v) for(auto&& V:v)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const int INF=1<<29;
const double EPS=1e-9;
using namespace std;


map<long long, long long> prime_factorization(long long n){
  map<long long, long long> factors;
  for(lint div=2; div*div <= n; ++div){
    if(n % div != 0) continue;
    int count = 0;
    while(n % div == 0){
      ++count;
      n /= div;
    }
    factors[div] = count;
  }
  if(n != 1) factors[n] = 1;
  return factors;
}

int main (void)
{
  lint n,p; cin>>n>>p;
  if(n==1){
    cout << p << endl;
    return 0;
  }
  map<lint,lint> factors = prime_factorization(p);
  // lint ans=1;
  // allrep(f,factors){
  //   rep(i,f.second/n) ans*=f.first;
  // }
  int ans=accumulate(all(factors), 1, [n](lint sum, lint f){return f.second<=n ? sum+f.first*(f.second/n) : sum});
  cout << ans << endl;
  return 0;
}


Compiler output:
a.cc: In lambda function:
a.cc:42:70: error: request for member 'second' in 'f', which is of non-class type 'lint' {aka 'long long int'}
   42 |   int ans=accumulate(all(factors), 1, [n](lint sum, lint f){return f.second<=n ? sum+f.first*(f.second/n) : sum});
      |                                                                      ^~~~~~
a.cc:42:88: error: request for member 'first' in 'f', which is of non-class type 'lint' {aka 'long long int'}
   42 |   int ans=accumulate(all(factors), 1, [n](lint sum, lint f){return f.second<=n ? sum+f.first*(f.second/n) : sum});
      |                                                                                        ^~~~~
a.cc:42:97: error: request for member 'second' in 'f', which is of non-class type 'lint' {aka 'long long int'}
   42 |   int ans=accumulate(all(factors), 1, [n](lint sum, lint f){return f.second<=n ? sum+f.first*(f.second/n) : sum});
      |                                                                                                 ^~~~~~
a.cc:42:112: error: expected ';' before '}' token
   42 |   int ans=accumulate(all(factors), 1, [n](lint sum, lint f){return f.second<=n ? sum+f.first*(f.second/n) : sum});
      |                                                                                                                ^
      |                                                                                                                ;
In file included from /usr/include/c++/14/numeric:62,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:58,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_numeric.h: In instantiation of '_Tp std::accumulate(_InputIterator, _InputIterator, _Tp, _BinaryOperation) [with _InputIterator = _Rb_tree_iterator<pair<const long long int, long long int> >; _Tp = int; _BinaryOperation = main()::<lambda(lint, lint)>]':
a.cc:42:21:   required from here
   42 |   int ans=accumulate(all(factors), 1, [n](lint sum, lint f){return f.second<=n ? sum+f.first*(f.second/n) : sum});
      |           ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_numeric.h:169:29: error: no match for call to '(main()::<lambda(lint, lint)>) (int&, std::pair<const long long int, long long int>&)'
  169 |         __init = __binary_op(_GLIBCXX_MOVE_IF_20(__init), *__first);
      |                  ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:42:39: note: candidate: 'main()::<lambda(lint, lint)>'
   42 |   int ans=accumulate(all(factors), 1, [n](lint sum, lint f){return f.second<=n ? sum+f.first*(f.second/n) : sum});
      |                                       ^
a.cc:42:39: note:   no known conversion for argument 2 from 'std::pair<const long long int, long long int>' to 'lint' {aka 'long long int'}