更好的阅读体验

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. 网络游戏开发-客户端2(自定义websocket协议格式)

    Egret官方提供了一个Websocket的库,可以让我们方便的和服务器长连接交互. 标题写的时候自定义websocket的协议格式.解释一下,不是说我们去动websocket本身的东西,我们是在we ...

  2. e课表项目第二次冲刺周期第八天

    昨天完成了什么? 昨天,我们组商量讨论了二层界面的设计,添加课程所需要的信息大概有:课程名称.教室.任课教师.上课时间.类型(单周.双周.单双周)以及备注等等.然后,我们通过界面的UI设计,让我们软件 ...

  3. jsonp 跨域Uncaught SyntaxError: Unexpected token :解决方法

    [jQuery]Ajax实现跨域访问JSON Ajax跨域访问JSON 环境:.net4.0+jQuery+JSON.net 因为在跨域实现,所以这里新建网站,这个网站只需要Ashx文件 public ...

  4. ubuntu下安装及配置git的方法

    安装Git 一个全新的ubunt系统,需要安装Git(系统是不具有该工具的),方法如下: 在terminel中输入如下命令: sudo apt-get install git git-core git ...

  5. PHP array_splice

    1.函数的作用:数组中元素的删除和替代 2.函数的参数: @params array  &$array @params int      $offset @params int      $l ...

  6. How to Compute The Derivatives (如何求导数)(TBC)

    A video by 3Blue1Brown in Bilibili\text{A video by 3Blue1Brown in Bilibili}A video by 3Blue1Brown in ...

  7. [HDU5001]Walk

    Problem Description I used to think I could be anything, but now I know that I couldn't do anything. ...

  8. eclipse中最有用的10个快捷键

    这里列出一些在使用eclipse的过程中最有用的10个快捷键,通过灵活使用这些快捷键可以提高开发效率和开发质量. 1. [ctrl+shift+r]打开资源 这可能是所有快捷键中最省时间的了.这个快捷 ...

  9. TensorFlow2.0(9):TensorBoard可视化

    .caret, .dropup > .btn > .caret { border-top-color: #000 !important; } .label { border: 1px so ...

  10. python如何判断一个对象是否是可迭代的?

    from collections import Iterable test_data = [{"type":1,"keyword":None}, {" ...