更好的阅读体验

Portal

Portal1: Codeforces

Portal2: Luogu

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 \le n \le 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

2

Sample Output

6

Solution

题目要我们构造\(1 \sim n\)位由\(7, 8\)的数的个数。我们先来找一找规律:

位数为\(1\)时:有\(7, 8\),共\(2 \times 2 ^ 0 = 2\)种;

位数为\(2\)时:有\(77, 78, 87, 88\),共\(2 \times 2 ^ 1 = 4\)种;

位数为\(3\)时:有\(777, 778, 787, 788, 877, 878, 887, 888\)共\(2 \times 2 ^ 2 = 8\)种;

\(\cdots \cdots\)

所以,位数是\(n\)的总个数是\(2 \times 2 ^ {n - 1}\);

那么位数为\(1 \sim n\)的总个数为

\[\begin{aligned} \sum^{n}_{i = 1}{2 \times 2 ^ {i - 1}} & = 2 \times \sum^{n}_{i = 1}{2 ^ {i - 1}} \\\\ & = 2 \times (2 ^ {n} - 2) \\\\ & = 2 ^ {n + 1} - 2\end{aligned}
\]

于是就解决了。

Code

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath> using namespace std; typedef long long LL;
LL n;
inline LL power(LL x, LL y) {//求x的y次方
LL ret = 1;
for (LL i = 1; i <= y; i++)
ret *= x;
return ret;
}
int main() {
scanf("%lld", &n);
printf("%lld\n", power(2, n + 1) - 2);//推出来的公式
return 0;
}

「CF630C」Lucky Numbers的更多相关文章

  1. 「CF55D」Beautiful numbers

    传送门 Luogu 解题思路 毒瘤数位DP,发现一个前缀我们只需要记录它对 \(\operatorname{lcm}(1,2,3,\cdots,9)=2520\) 取模的值即可,所以我们在 DP 时记 ...

  2. 「CF446C」 DZY Loves Fibonacci Numbers

    「CF446C」 DZY Loves Fibonacci Numbers 这里提供一种优美的根号分治做法. 首先,我们考虑一种不太一样的暴力.对于一个区间加斐波那契数的操作 \([a,b]\),以及一 ...

  3. 「2014-2-26」Unicode vs. UTF-8 etc.

    目测是个老问题了.随便一搜,网上各种总结过.这里不辞啰嗦,尽量简洁的备忘一下. 几个链接,有道云笔记链接,都是知乎上几个问题的摘录:阮一峰的日志,1-5 还是值得参考,但是之后的部分则混淆了 Wind ...

  4. 「USACO16OPEN」「LuoguP3147」262144(区间dp

    P3147 [USACO16OPEN]262144 题目描述 Bessie likes downloading games to play on her cell phone, even though ...

  5. 「MoreThanJava」一文了解二进制和CPU工作原理

    「MoreThanJava」 宣扬的是 「学习,不止 CODE」,本系列 Java 基础教程是自己在结合各方面的知识之后,对 Java 基础的一个总回顾,旨在 「帮助新朋友快速高质量的学习」. 当然 ...

  6. 「MoreThanJava」Day 3:构建程序逻辑的方法

    「MoreThanJava」 宣扬的是 「学习,不止 CODE」,本系列 Java 基础教程是自己在结合各方面的知识之后,对 Java 基础的一个总回顾,旨在 「帮助新朋友快速高质量的学习」. 当然 ...

  7. 「译」JUnit 5 系列:条件测试

    原文地址:http://blog.codefx.org/libraries/junit-5-conditions/ 原文日期:08, May, 2016 译文首发:Linesh 的博客:「译」JUni ...

  8. 「译」JUnit 5 系列:扩展模型(Extension Model)

    原文地址:http://blog.codefx.org/design/architecture/junit-5-extension-model/ 原文日期:11, Apr, 2016 译文首发:Lin ...

  9. JavaScript OOP 之「创建对象」

    工厂模式 工厂模式是软件工程领域一种广为人知的设计模式,这种模式抽象了创建具体对象的过程.工厂模式虽然解决了创建多个相似对象的问题,但却没有解决对象识别的问题. function createPers ...

随机推荐

  1. 直通BAT面试题库锦集

    01 python面试题(汇总) 02 面向对象 03 网络和并发编程 04 模块 05 设计模式 06 前端 07 Django框架 08 Flask 09 tornado 10 DB

  2. 【TencentOS tiny】深度源码分析(3)——队列

    队列基本概念 队列是一种常用于任务间通信的数据结构,队列可以在任务与任务间.中断和任务间传递消息,实现了任务接收来自其他任务或中断的不固定长度的消息,任务能够从队列里面读取消息,当队列中的消息是空时, ...

  3. 最新打赏正版V15微信视频打赏源码 带(百倍)暗雷 N秒试看 自动切换域名 自动防封

    免签支付域名防封随机跳转盒子推广设置试看N秒百倍 平台搭建:乌龟-源码科技QQ:64430146 全新版本 V15打赏版本功能介绍: 特别注意: 新增加功能!!!! 1.包括V14所有功能(除个别因优 ...

  4. Python历史+优缺点+应用领域+网站职位简介

    一.Python的历史 1. 1989年圣诞节:Guido von Rossum开始写Python语言的编译器.2. 1991年2月:第一个Python编译器(同时也是解释器)诞生,它是用C语言实现的 ...

  5. 无 PowerShell.exe 执行 Empire 的几种姿势

    在实战中,Empire成为域渗透.后渗透阶段一大利器,而Empire是一个Powershell RAT,所以PowerShell必须要能运行Empire中几乎所有的启动方法都依赖于使用PowerShe ...

  6. windows 7 专业版 64位 无法安装.Net 4.7版本解决方案

    什么暂停windows update,改文件夹,再恢复windows update等等方法都试了,不行之后就觉得这才是终极解决方案. 不管你是win 7什么版本,你只需要下载安装对应系统的Window ...

  7. [Luogu3878] [TJOI2010]分金币

    题目描述 现在有n枚金币,它们可能会有不同的价值,现在要把它们分成两部分,要求这两部分金币数目之差不超过1,问这样分成的两部分金币的价值之差最小是多少? 输入输出格式 输入格式: 每个输入文件中包含多 ...

  8. [Luogu3069][USACO13JAN]牛的阵容Cow Lineup

    题目描述 Farmer John's N cows (1 <= N <= 100,000) are lined up in a row. Each cow is identified by ...

  9. [BZOJ1202] [NZOI2005]狡猾的商人

    Description 刁姹接到一个任务,为税务部门调查一位商人的账本,看看账本是不是伪造的.账本上记录了n个月以来的收入情况,其中第i 个月的收入额为Ai(i=1,2,3...n-1,n), .当 ...

  10. 【阿里云IoT+YF3300】6.物联网设备报警配置

    纵然5G时代已经在时代的浪潮中展现出了它的身影,但是就目前的物联网环境中,网络问题仍旧是一个比较突出的硬伤.众所周知,在当前的物联网规划中,与其说是实现万物互联,倒不如说是行业指标数据监控.对于一些特 ...