首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >【周练2016.3.7】B - Lucky Numbers(位运算,水)

【周练2016.3.7】B - Lucky Numbers(位运算,水)

作者头像
FishWang
发布2025-08-27 08:46:16
发布2025-08-27 08:46:16
9400
代码可运行
举报
运行总次数:0
代码可运行

B - Lucky Numbers

Time Limit:500MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u

Description  The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers.

Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in the new building of the Tax Office given that a door-plate can hold a number not longer than n digits.

Input  The only line of input contains one integer n (1 ≤ n ≤ 55) — the maximum length of a number that a door-plate can hold.

Output  Output one integer — the maximum number of offices, than can have unique lucky numbers not longer than n digits.

Sample Input  Input  2  Output  6

题意:给出变量n,表示最多有n位,这n位只能由7或8组成,问有多少种组成方法。

解题:每一位都可以是7或8,n位的数有2的n次方种,n-1位有2的n-1次方种,依次类推,直到1位(2种)。

    要输出的结果即为2为首项2为公比的前n项和。

    化简后,公式为:2*(2 ² - 1)/ / 科普:上标的输入方法:按住ALT,然后在小键盘输入0178(这里不知道为啥总是变成上标2,改正一下,应该是n)

    化简完还要注意a的范围,要用longlong型。

代码如下:

代码语言:javascript
代码运行次数:0
运行
复制
#include <cstdio>
int main()
{
	long long a;
	a=2;
	int n;
	scanf ("%d",&n);
	a<<=n-1;
	a=(a-1)*2;
	printf ("%lld",a);
	return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016-03-07,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • B - Lucky Numbers
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档