数列
这道题规律简单,但需要映射才能变得更好写点,直接当成二进制操作即可
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int power(int a,int b)
{
int res = 1;
while(b --) res *= a;
return res;
}
int main()
{
int k,n;
scanf("%d%d",&k,&n);
int res = 0;
for(int i = 0;i < 10 ;i ++)
if(n >> i & 1)
res += power(k,i);
cout<<res<<endl;
return 0;
}