Language: C++

#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

constexpr Int mod = 1e9+7;
vector<Int> p;

Int calc_nod(Int n){
	Int cnt = 0;
	for(auto i:p){
		if(i > n) break;
		if(n % i == 0){
			++cnt;
			n /= i;
			if(n % i == 0){
				cnt = -1e9;
			}
		}
	}
	return max(cnt, 0ll);
}

Int calc_pn(Int m, Int n){
	Int res = 1;
	while(n > 0){
		if((n & 1) == 1){
			res = res * m % mod;
		}
		m = m * m % mod;
		n >>= 1;
	}
	return res;
}

Int func(Int m, vector<Int> &pn, vector<Int> &nod){
	Int res = pn[m];
	for(Int i=2; i<=m; ++i){
		if(nod[i] == 0) continue;
		res = (res + (1-2*(nod[i]%2)) * pn[m/i] + mod) % mod;
	}
	return res;
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	Int n, k; cin >> n >> k;
	for(Int i=2; i<=k; ++i){
		bool f = true;
		for(auto j:p){
			if(i % j == 0){
				f = false;
				break;
			}
		}
		if(f) p.push_back(i);
	}
	vector<Int> nod(k+1);
	for(Int i=1; i<=k; ++i)
	nod[i] = calc_nod(i);
	vector<Int> pn(k+1);
	for(Int i=1; i<=k; ++i)
		pn[i] = calc_pn(i, n);
//	for(Int i=1; i<=k; ++i)
//		cout << i << " " << pn[i] << "\n";
	Int ans = 0;
	for(Int i=1; i<=k; ++i){
//		cout << i << " " << func(k/i, pn, nod) << "\n";
		ans = (ans + i * func(k/i, pn, nod) % mod) % mod;
	}
	cout << ans << "\n";
}

Compiler output:
a.cc: In function 'Int calc_nod(Int)':
a.cc:20:19: error: no matching function for call to 'max(Int&, long long int)'
   20 |         return max(cnt, 0ll);
      |                ~~~^~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:20:19: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
   20 |         return max(cnt, 0ll);
      |                ~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:20:19: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   20 |         return max(cnt, 0ll);
      |                ~~~^~~~~~~~~~