您的位置:首页 > 其它

|洛谷|NOIP2006|模拟|P1062 数列

2016-10-04 16:21 267 查看
3^0,3^1,3^0+3^1,3^2,3^0+3^2,3^1+3^2,3^0+3^1+3^2

把i转化为2进制,i为第几项数

对应于上面

1 10 11 100 101 110 111

找到规律,把n转为2进制即可解决

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#define ms(i,j) memset(i,j, sizeof i);
using namespace std;
int main()
{
int k,n;
scanf("%d%d", &k, &n);
int ans = 0;
int base = 1;
while (n!=0)
{
if (n&1)
{
ans += base;
}
base *= k;
n>>=1;
}
printf("%d\n", ans);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: