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
output
input
output
input
output
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的最大值是1e8,2^30一定能比m大,所以最多循环30次,如
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; }
相关文章推荐
- Fast modular exponentiation
- A. Modular Exponentiation
- codeforces 913 A Modular Exponentiation
- Fast Modular Exponentiation
- A. Modular Exponentiation
- Eclipse+ GNU ARM Eclipse Plug-in+ Sourcery G++ Lite Edition for ARM+OPENCD+Jlink
- linux 下安装gsl(GNU Scientific Library)
- Gnu/Linux/ubuntu下卸载软件
- Java程序练习-Exponentiation
- Gnu gprof
- HDOJ 1063 Exponentiation
- HDU 1063 - Exponentiation
- 【POJ】1001 Exponentiation
- 一个简单的GNU assert用法测试程序
- GNU C Compiler Internals/GNU C Compiler Architecture(GNU C编译器内部结构/架构)
- poj 1001 Exponentiation 五个小时。。。回来重写
- cygwin+linux+GNU工具命令 2
- [zz]64bit Linux下error: gnu/stubs-32.h: No such file or directory错误解决办法
- Ruby作者和GNU Health获2011年自由软件奖
- GNUstep Gorm第一个视窗程序,第一个图形界面,第一个helloworld gui