Codeforces--630C--Lucky Numbers(快速幂)
Lucky Numbers
Crawling in process...
Crawling failed
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
2
6
数字中只含有7或者8的成为Lucky Numbers,问n位以内的数字有多少个Lucky Numbers,总数应该就是2+2^2+....+2^n,数学公式变形之后就是2^(n+1)-2个,n+1可能比较大,所以快速幂解决
#include<iostream>
using namespace std;
#define LL long long
LL p(LL x, LL n)
{
LL pw = 1;
while (n > 0)
{
if (n & 1)
pw *= x;
x *= x;
n >>= 1;
}
return pw;
}
int main()
{
LL n;
LL num;
cin>>n;
cout<<p(2,n+1)-2<<endl;
return 0;
}
Codeforces--630C--Lucky Numbers(快速幂)的更多相关文章
- codeforces 630C - Lucky Numbers 递推思路
630C - Lucky Numbers 题目大意: 给定数字位数,且这个数字只能由7和8组成,问有多少种组合的可能性 思路: 假设为1位,只有7和8:两位的时候,除了77,78,87,88之外还哇哦 ...
- codeforces 630C Lucky Numbers
C. Lucky Numbers time limit per test 0.5 seconds memory limit per test 64 megabytes input standard i ...
- CodeForces 185A. Plant (矩阵快速幂)
CodeForces 185A. Plant (矩阵快速幂) 题意分析 求解N年后,向上的三角形和向下的三角形的个数分别是多少.如图所示: N=0时只有一个向上的三角形,N=1时有3个向上的三角形,1 ...
- CF1096. G. Lucky Tickets(快速幂NTT)
All bus tickets in Berland have their numbers. A number consists of n digits (n is even). Only k dec ...
- CodeForces 450B (矩阵快速幂模板题+负数取模)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=51919 题目大意:斐波那契数列推导.给定前f1,f2,推出指定第N ...
- POJ3641 Pseudoprime numbers(快速幂+素数判断)
POJ3641 Pseudoprime numbers p是Pseudoprime numbers的条件: p是合数,(p^a)%p=a;所以首先要进行素数判断,再快速幂. 此题是大白P122 Car ...
- POJ1995 Raising Modulo Numbers(快速幂)
POJ1995 Raising Modulo Numbers 计算(A1B1+A2B2+ ... +AHBH)mod M. 快速幂,套模板 /* * Created: 2016年03月30日 23时0 ...
- pojPseudoprime numbers (快速幂)
Description Fermat's theorem states that for any prime number p and for any integer a > 1, ap = a ...
- POJ 1995:Raising Modulo Numbers 快速幂
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5532 Accepted: ...
- codeforces 691E Xor-sequences 矩阵快速幂
思路:刚开始 n个元素,a[i][j]代表以i开头,j结尾的二元组符合条件的有多少 这是等于长度为2的数量 长度为3的数量为a*a,所以长度为n的数量是a^(k-1) 然后就是矩阵快速幂,然而我并不能 ...
随机推荐
- Centos 安装配置iscsi
在测试oracle rac的时候用iscsi来模拟磁阵的(真的磁阵需要多路径软件),简单的记录下 #scsi server yum install scsi-target-utils service ...
- (转)分布式文件存储FastDFS(五)FastDFS常用命令总结
http://blog.csdn.net/xingjiarong/article/details/50561471 1.启动FastDFS tracker: /usr/local/bin/fdfs_t ...
- Sandbox 沙盒
In computer security, a sandbox is a security mechanism for separating running programs, usually in ...
- 解决richfaces自带的jquery
项目里有个有史以来让人头疼的问题,就是前端的richfaces框架自带有jquery插件,而且好像总是在最后才加载,导致前面自己加载好的jquery版本的框架以及应用到jquery的其他前端框架生成的 ...
- centOS7卸载google-chrome
参考: https://www.jianshu.com/p/39d0b8f578d9
- final关键字用法
Java关键字final有“这是无法改变的”或者“终态的”含义,它可以修饰非抽象类.非抽象类成员方法和变量. final类不能被继承,没有子类,final类中的方法默认是final的. final方法 ...
- ceph对接openstack环境
环境准备: 保证openstack节点的hosts文件里有ceph集群的各个主机名,也要保证ceph集群节点有openstack节点的各个主机名 一.使用rbd方式提供存储如下数据: (1)image ...
- [ZJOJ] 5794 2018.08.10【2018提高组】模拟A组&省选 旅行
Description 悠悠岁月,不知不觉,距那传说中的pppfish晋级泡泡帝已是过 去数十年.数十年 中,这颗泡泡树上,也是再度变得精彩,各种泡泡 天才辈出,惊艳世人,然而,似乎 不论后人如何的出 ...
- 8.1.2 Cursor 对象
游标Cursor也是sqlite3模块中比较重要的一个类,下面简单介绍下Cursor对象的常用方法. 1 execute(sql[,parameters]) 该方法用于执行一条SQL语句,下面的代码演 ...
- hdu 1532&&poj1273 基础最大流
#include<stdio.h> #include<string.h> #include<queue> #include<iostream> usin ...