您的位置:首页 > 其它

913A - Modular Exponentiation GNU

2018-01-09 10:59 169 查看
A. Modular Exponentiation

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

The following problem is well-known: given integers n and m,
calculate


,

where 2n = 2·2·...·2 (n factors),
and 

 denotes
the remainder of division of x by y.

You are asked to solve the "reverse" problem. Given integers n and m,
calculate


.

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 

.

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 mod 2^n。

题解:暴力  因为m的最大值是1e8,2^30一定能比m大,所以最多循环30次,如

果2^n大于m,就输出m,小于的话,m mod 2^n。今天早上看别人的代码,居然还能直接用pow,心里阴影面积贼大,pow函数是有精度误差的,然后当n太大能行么?可能是我想多了,昨晚看小紫书,还在找算法的,结果就是暴力。但是pow。。。不说了。。。

#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n,m,num;
cin>>n>>m;
num=1;
for(int i=1; i<=n; i++)
{
num<<=1;
if(num>m)
{
cout<<m<<endl;
return 0;
}
}
cout<<m%num<<endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: