Skip to content

Instantly share code, notes, and snippets.

@chermehdi
Created November 19, 2017 15:29
Show Gist options
  • Save chermehdi/6607196e8bbdb4c3af374ac232c57488 to your computer and use it in GitHub Desktop.
Save chermehdi/6607196e8bbdb4c3af374ac232c57488 to your computer and use it in GitHub Desktop.
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author MaxHeap
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastReader in = new FastReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
static class TaskB {
long mod = (long) 1e9 + 7L;
public void solve(int testNumber, FastReader in, PrintWriter out) {
long n = in.nextLong();
long m = in.nextLong();
long ans = LongMath.powMod(2L, n - 1, mod);
ans = LongMath.powMod(ans, m - 1, mod);
out.println(ans);
}
}
static class FastReader {
BufferedReader reader;
StringTokenizer st;
public FastReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
st = null;
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
String line = reader.readLine();
if (line == null) {
return null;
}
st = new StringTokenizer(line);
} catch (Exception e) {
throw new RuntimeException();
}
}
return st.nextToken();
}
public long nextLong() {
return Long.parseLong(next());
}
}
static class LongMath {
private LongMath() {
}
public static long powMod(long base, long power, long Mod) {
base %= Mod;
long res = 1L;
while (power != 0) {
if ((power & 1) != 0) {
res = (res * base) % Mod;
}
base = (base * base) % Mod;
power >>= 1;
}
return res;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment