要求:
https://www.dotcpp.com/oj/problem1105.html
emmm这题真的是比较巧妙= =(PS刷这些巧的题,真的有价值么。。)
参考大神的思路,转成二进制的规律来处理
题解:
https://blog.dotcpp.com/a/62970
AC代码:
#include <stdio.h>
#include <algorithm>
#include <math.h>
using namespace std;
int main(){
int k,N,sum = 0,i = 0;
scanf("%d %d",&k,&N);
while(N>0){
if(N %2 == 1){
int m = 1;
for(int j = 1;j<=i;j++){
m = m *k;
}
sum = sum + m;
}
i++;
N = N/2;
}
printf("%d",sum);
}