更好的阅读体验

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. 【POJ2001】Shortest Prefixes

    Shortest Prefixes Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 18724   Accepted: 810 ...

  2. JAVA阻塞(IO)和非阻塞(NIO)

    查看这篇文章,了解更多关于Java的阻塞和非阻塞替代创建套接字的信息. 套接字使用TCP / IP传输协议,是两台主机之间的最后一块网络通信. 您通常不必处理它们,因为它们之上构建了协议,如HTTP或 ...

  3. Numpy中的一点小知识

    train_set_x_orig, train_set_y, test_set_x_orig, test_set_y, classes = load_dataset()train_set_x_orig ...

  4. MySQL从库生成大量小的relay log案例模拟

    最近看到"八怪"写的<MySQL:产生大量小relay log的故障一例>,因之前也遇到类似的情况,一直没搞懂原理及复现,看完此文章后,本着实践是检验真理的唯一标准的原 ...

  5. 安装VMware Tools显示灰色正确解决办法

    首先问题如下: 解决办法如下:1.关闭虚拟机: 2.在虚拟机设置分别设置CD/DVD.CD/DVD2和软盘为自动检测三个步骤: 3.再重启虚拟机,灰色字即点亮. 大功告成,如果解决了你的问题,点个赞鼓 ...

  6. [LUOGU1272] 重建道路 - 树形背包

    题目描述 一场可怕的地震后,人们用N个牲口棚(1≤N≤150,编号1..N)重建了农夫John的牧场.由于人们没有时间建设多余的道路,所以现在从一个牲口棚到另一个牲口棚的道路是惟一的.因此,牧场运输系 ...

  7. python soket服务和客户端Demo

    #服务端from socket import * s=socket(AF_INET,SOCK_STREAM)#IVP4 寻址 tcp协议 s.bind(('',6666))#补丁端口 s.listen ...

  8. python编程系列---最详细的讲解进程与线程的关系

    进程与线程 先引入三个比如: cpu---公司 进程---办公室   线程---程序员(我们)   全局变量,内存等资源---公司提供的电脑,桌子等 进程:  操作系统分配程序执行资源的单位 线程:进 ...

  9. .NET如何将字符串分隔为字符

    .NET如何将字符串分隔为字符 如果这是一道面试题,答案也许非常简单:.ToCharArray(),这基本正确-- 我们以"AB吉

  10. maven的相关操作及常见问题

    mvn本地服务nexus3的搭建 下载 下载nexus 官网速度极慢,下面是我下好上传的大家可以下载使用链接:https://pan.baidu.com/s/1Ji5Orv3moXc60HRQ39y6 ...