|洛谷|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;
}
把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;
}
相关文章推荐
- [NOIP2006] 提高组 洛谷P1066 2^k进制数
- 洛谷 1064 [NOIP2006] 金明的预算方案 背包DP
- 洛谷1071 潜伏者 NOIP2009 字符串模拟
- |洛谷|NOIP2006|排序|P1059 明明的随机数
- NOIP模拟10.21(洛谷10月R2)
- NOIP2006普及组-数列
- 洛谷 3938 [NOIP模拟] 斐波那契 二分+找规律
- 数列 洛谷p1062
- 【NOIP2013模拟联考7】数列
- 洛谷 P1062 数列
- |洛谷|NOIP2011|模拟|P1003 铺地毯
- 洛谷1071 潜伏者 NOIP2009 字符串模拟
- 洛谷 1063 [NOIP2006] 能量项链 DP
- Noip 1998 洛谷P1011 车站 - 模拟
- 洛谷 NOIP 模拟 DAY1
- 洛谷 P1065 [NOIP2006 T3] 作业调度方案
- 洛谷 P1063 [NOIP2006 T1] 能量项链
- 【模拟】洛谷 P1181 数列分段Section I
- 洛谷 P1062 数列
- 洛谷1071 潜伏者 NOIP2009 字符串模拟