题目地址


#include<cstdio>
#include<iostream>
#define int long long
using namespace std;

int poww(int a,int b){
	int ans=1,tmp=a;
	while(b){
		if(b&1)ans*=tmp;
		tmp*=tmp;
		b>>=1;
	}
	return ans;
}

signed main(){
	int k,n;
	cin>>k>>n;
	int ans=0;
	int cnt=0;
	while(n){
		if(n&1)ans+=poww(k,cnt);
		cnt++;
		n>>=1;
	}
	cout<<ans<<endl;
	return 0;
}