F - Modular Exponentiation
Problem description
The following problem is well-known: given integers n and m, calculate 2n mod m,
where 2n = 2·2·...·2 (n factors), and x mod y denotes the remainder of division of x by y.
You are asked to solve the "reverse" problem. Given integers n and m, calculate m mod 2n.
Input
The first line contains a single integer n (1 ≤ n ≤ 108).
The second line contains a single integer m (1 ≤ m ≤ 108).
Output
Output a single integer — the value of m mod 2n.
Examples
Input
4
42
Output
10
Input
1
58
Output
0
Input
98765432
23456789
Output
23456789
Note
In the first example, the remainder of division of 42 by 24 = 16 is equal to 10.
In the second example, 58 is divisible by 21 = 2 without remainder, and the answer is 0.
解题思路:由于给出的m最大值为108,于是暴力找出2k>108时的最小值k,解得k=27,所以只要n>26,直接输出m(取模一个比自己大的数字,结果为本身),反之直接取模运算,这样就不会发生数据溢出。(位运算是个好东西,长记性了)
AC代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
cout<<(n>?m:m%(<<n))<<endl;
return ;
}
F - Modular Exponentiation的更多相关文章
- 焦作F Modular Production Line 费用流
题目链接 题解:这道题比赛的时候,学弟说是网络流,当时看N这么大,觉得网络流没法做,实际本题通过巧妙的建图,然后离散化. 先说下建图方式,首先每个覆盖区域,只有左右端点,如果我们只用左右端点的话,最多 ...
- ACM-ICPC 2018 焦作赛区网络预赛 F. Modular Production Line (区间K覆盖-最小费用流)
很明显的区间K覆盖模型,用费用流求解.只是这题N可达1e5,需要将点离散化. 建模方式步骤: 1.对权值为w的区间[u,v],加边id(u)->id(v+1),容量为1,费用为-w; 2.对所有 ...
- 【Hello 2018 A】 Modular Exponentiation
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 当a<b的时候 a%b==a 显然2^n增长很快的. 当2^n>=1e8的时候,直接输出m就可以了 [代码] #incl ...
- RSA算法原理与加密解密 求私钥等价求求模反元素 等价于分解出2个质数 (r*X+1)%[(p-1)(q-1)]=0
Rsapaper.pdf http://people.csail.mit.edu/rivest/Rsapaper.pdf [概述Abstract 1.将字符串按照双方约定的规则转化为小于n的正整数m, ...
- RSA (cryptosystem)
https://en.wikipedia.org/wiki/RSA_(cryptosystem) RSA is one of the first practical实用性的 public-key cr ...
- Effective Java 第三版——17. 最小化可变性
Tips <Effective Java, Third Edition>一书英文版已经出版,这本书的第二版想必很多人都读过,号称Java四大名著之一,不过第二版2009年出版,到现在已经将 ...
- SSL加速卡调研的原因及背景
SSL加速卡调研的原因及背景 SSL加速卡调研的原因及背景 网络信息安全已经成为电子商务和网络信息业发展的一个瓶颈,安全套接层(SSL)协议能较好地解决安全处理问题,而SSL加速器有效地提高了网络安全 ...
- 2018 ACM 网络选拔赛 焦作赛区
A. Magic Mirror #include <cstdio> #include <cstdlib> #include <cmath> #include < ...
- Hello 2018 A,B,C,D
A. Modular Exponentiation time limit per test 1 second memory limit per test 256 megabytes input sta ...
随机推荐
- springboot配置多数据源(JdbcTemplate方式)
在实际开发中可能会遇到需要配置多个数据源的情况,比如:需要使用多个host.需要使用多种数据库(MySql.Oracle.SqlServer…) 如果使用springboot开发,可做如下配置: Co ...
- 4.Linux的进程
4.1 Linux的进程 4.1.1 进程的概述 有关进程的一些基本概念: 1.什么是进程: 当程序被触发后,执行者的权限与属性.程序的程序代码与所需的数据都会被加载到内存中,操作系统并给予这个内存内 ...
- php第十三节课
查询 <?php class DBDA{ public $host = "localhost"; //数据库地址 public $uid = "root" ...
- Java学习【第1篇】:数据类型(2019-02-13 11:00)
1.Java 基本数据类型 Java 的两大数据类型: 1.内置数据类型 byte.short.int.long.float.double.boolean.char 2.引用数据类型 指向一个对象, ...
- POJ3984——迷宫问题
迷宫问题 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 31616 Accepted: 18100 Descriptio ...
- (39.4) Spring Boot Shiro权限管理【从零开始学Spring Boot】
在读此文章之前您还可能需要先了解: (39.1) Spring Boot Shiro权限管理[从零开始学Spring Boot] http://412887952-qq-com.iteye.com/b ...
- mode-c++
/*感谢机房JYW的友情馈赠*/#include <iostream> #include <cstdio> #include <cstring> #include ...
- 嵌入式linux和嵌入式android系统有什么区别和联系?
转自:http://bbs.eeworld.com.cn/thread-430437-1-1.html 这个问题很多人问,尤其是初入嵌入式的菜鸟.其实大家都认为android是java,已经不是lin ...
- nyoj_915_+-字符串_201402261520
+-字符串 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描述 Shiva得到了两个只有加号和减号的字符串,字串长度相同.Shiva一次可以把一个加号和 ...
- [bzoj4282]慎二的随机数列_动态规划_贪心
慎二的随机数列 bzoj-4282 题目大意:一个序列,序列上有一些数是给定的,而有一些位置上的数可以任意选择.问最长上升子序列. 注释:$1\le n\le 10^5$. 想法:结论:逢N必选.N是 ...