Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M=1e9+7,N=100010;
ll n,k,ans;
ll gcd[N];
ll prime[N];
bool isp[N];
ll exp(ll base,ll ex,ll mod){
	if(ex==0) return 1;
	ll tmp=exp(base,ex>>1,mod);
	tmp=tmp*tmp%mod;
	if(ex&1) return tmp*base%mod;
	return tmp;
}
ll num(ll x){
	ll tmp=0;
	for(ll i=1;prime[i]<=x;++i){
		if(x%prime[i]==0){
			++tmp;
			while(x%prime[i]==0){
				x/=prime[i];
			}
		}
	}
	return tmp-1;
}
int main()
{
	scanf("%lld%lld",&n,&k);
	for(ll i=2;i<N;++i) isp[i]=true;
	for(ll i=2;i<N;++i){
		if(isp[i]){
			prime[++prime[0]]=i;
		}
		for(ll j=1;j<=prime[0]&&prime[j]*i<N;++j){
			isp[prime[j]*i]=false;
			if(i%prime[j]==0) break;
		}
	}
	for(ll g=1;g<=k;++g){
		if(g>1){
			if(k/g==k/(g-1)) gcd[g]=gcd[g-1];
		}
		gcd[g]=exp(k/g,n,M);
		//printf("gcd[%lld]=%lld\n",g,gcd[g]);
	}
	for(ll g=k;g>=1;--g){
		for(ll i=2;i*g<=k;++i){
			gcd[g]-=gcd[g*i];
			if(gcd[g]<0) gcd[g]+=M;
		}
		//printf("gcd[%lld]=%lld\n",g,gcd[g]);
	}
	for(ll g=1;g<=k;++g){
		ans+=gcd[g]*g%M;
		ans%=M;
	}
	printf("%lld",ans);
}

Compiler output:
a.cc: In function 'int main()':
a.cc:43:42: error: reference to 'gcd' is ambiguous
   43 |                         if(k/g==k/(g-1)) gcd[g]=gcd[g-1];
      |                                          ^~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:58,
                 from a.cc:1:
/usr/include/c++/14/numeric:173:5: note: candidates are: 'template<class _Mn, class _Nn> constexpr std::common_type_t<_Mn, _Nn> std::gcd(_Mn, _Nn)'
  173 |     gcd(_Mn __m, _Nn __n) noexcept
      |     ^~~
a.cc:6:4: note:                 'll gcd [100010]'
    6 | ll gcd[N];
      |    ^~~
a.cc:43:49: error: reference to 'gcd' is ambiguous
   43 |                         if(k/g==k/(g-1)) gcd[g]=gcd[g-1];
      |                                                 ^~~
/usr/include/c++/14/numeric:173:5: note: candidates are: 'template<class _Mn, class _Nn> constexpr std::common_type_t<_Mn, _Nn> std::gcd(_Mn, _Nn)'
  173 |     gcd(_Mn __m, _Nn __n) noexcept
      |     ^~~
a.cc:6:4: note:                 'll gcd [100010]'
    6 | ll gcd[N];
      |    ^~~
a.cc:45:17: error: reference to 'gcd' is ambiguous
   45 |                 gcd[g]=exp(k/g,n,M);
      |                 ^~~
/usr/include/c++/14/numeric:173:5: note: candidates are: 'template<class _Mn, class _Nn> constexpr std::common_type_t<_Mn, _Nn> std::gcd(_Mn, _Nn)'
  173 |     gcd(_Mn __m, _Nn __n) noexcept
      |     ^~~
a.cc:6:4: note:                 'll gcd [100010]'
    6 | ll gcd[N];
      |    ^~~
a.cc:50:25: error: reference to 'gcd' is ambiguous
   50 |                         gcd[g]-=gcd[g*i];
      |                         ^~~
/usr/include/c++/14/numeric:173:5: note: candidates are: 'template<class _Mn, class _Nn> constexpr std::common_type_t<_Mn, _Nn> std::gcd(_Mn, _Nn)'
  173 |     gcd(_Mn __m, _Nn __n) noexcept
      |     ^~~
a.cc:6:4: note:                 'll gcd [100010]'
    6 | ll gcd[N];
      |    ^~~
a.cc:50:33: error: reference to 'gcd' is ambiguous
   50 |                         gcd[g]-=gcd[g*i];
      |                                 ^~~
/usr/include/c++/14/numeric:173:5: note: candidates are: 'template<class _Mn, class _Nn> constexpr std::common_type_t<_Mn, _Nn> std::gcd(_Mn, _Nn)'
  173 |     gcd(_Mn __m, _Nn __n) noexcept
      |     ^~~
a.cc:6:4: note:                 'll gcd [100010]'
    6 | ll gcd[N];
      |    ^~~
a.cc:51:28: error: reference to 'gcd' is ambiguous
   51 |                         if(gcd[g]<0) gcd[g]+=M;
      |                            ^~~
/usr/include/c++/14/numeric:173:5: note: candidates are: 'template<class _Mn, class _Nn> constexpr std::common_type_t<_Mn, _Nn> std::gcd(_Mn, _Nn)'
  173 |     gcd(_Mn __m, _Nn __n) noexcept
      |     ^~~
a.cc:6:4: note:                 'll gcd [100010]'
    6 | ll gcd[N];
      |    ^~~
a.cc:51:38: error: reference to 'gcd' is ambiguous
   51 |                         if(gcd[g]<0) gcd[g]+=M;
      |                                      ^~~
/usr/include/c++/14/numeric:173:5: note: candidates are: 'template<class _Mn, class _Nn> constexpr std::common_type_t<_Mn, _Nn> std::gcd(_Mn, _Nn)'
  173 |     gcd(_Mn __m, _Nn __n) noexcept
      |     ^~~
a.cc:6:4: note:                 'll gcd [100010]'
    6 | ll gcd[N];
      |    ^~~
a.cc:56:22: error: reference to 'gcd' is ambiguous
   56 |                 ans+=gcd[g]*g%M;
      |                      ^~~
/usr/include/c++/14/numeric:173:5: note: candidates are: 'template<class _Mn, class _Nn> constexpr std::common_type_t<_Mn, _Nn> std::gcd(_Mn, _Nn)'
  173 |     gcd(_Mn __m, _Nn __n) noexcept
      |     ^~~
a.cc:6:4: note:                 'll gcd [100010]'
    6 | ll gcd[N];
      |    ^~~