Problem:


Power

For given integers m and n, compute mn (mod 1,000,000,007). Here, A (mod M) is the remainder when A is divided by M.

Input

m n

Two integers m and n are given in a line.

Output

Print mn (mod 1,000,000,007) in a line.

Constraints

1 ≤ m ≤ 100

1 ≤ n ≤ 109

Sample Input 1

2 3

Sample Output 1

8

Sample Input 2

5 8

Sample Output 2

390625



Sample input:
2 3


Sample output:
8

Submission status: Accepted

Solution code:
MAX = 1000000007

m, n = [int(x) for x in input().split(' ')]
bi_n = bin(n)

ans = 1
dig = m
for i in range(len(bi_n)-1, 1, -1):
    if bi_n[i] == '1': ans *= dig
    if ans >= MAX: ans %= MAX
    dig *= dig
    if dig >= MAX: dig %= MAX

print(ans)

Submission status: Accepted

Solution code:
m, n = map(int, input().split())
print(pow(m, n, int(1e9) + 7))

Submission status: Accepted

Solution code:
mod = 1000000007
l = input().split()
m = int(l[0])
n = int(l[1])


def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % mod
    elif y % 2 == 0:
        return power(x, y/2)**2 % mod
    else:
        return power(x, int(y/2))**2 * x % mod


ans = power(m, n)
print(ans)

Submission status: Accepted

Solution code:
m,n=[ int(x) for x in input().split()]    
k=1000000007

REM={}

def remainder(i):

    if i in REM.keys():
        return REM[i]

    if i==1:
        re=m%k
        REM[1]=re     
        return re

    if i==2:
        re=(m%k)**2%k
        REM[2]=re        
        return re
    
    left=i//2
    right=i-left
    REM[i]=remainder(left)*remainder(right)%k
    return REM[i]


print(remainder(n))

Submission status: Accepted

Solution code:
m,n = map(int,input().split(" "))
print(pow(m,n,1000000007))

Submission status: Accepted

Solution code:
mod = 1000000007

def mod_power(a, n):
    if n == 0:
        return 1
    if n % 2:
        return a * mod_power(a, n - 1) % mod
    tmp = mod_power(a, n // 2)
    return tmp * tmp % mod


a, n = [int(i) for i in input().split()]
print(mod_power(a, n))

Submission status: Accepted

Solution code:
def main():
    m, n = [int(_) for _ in input().split()]
    print(pow(m, n, 1000000007))

main()

Submission status: Accepted

Solution code:
a, b = raw_input().split()
print pow(int(a), int(b), 1000000007)

Submission status: Accepted

Solution code:
l = 1000000007
n,m = map(int,raw_input().split())
print pow(n,m,l)

Submission status: Accepted

Solution code:
n,m = map(int,raw_input().split())
print pow(n,m,1000000007)

Submission status: Accepted

Solution code:
m, n = map(int, input().split())

print(pow(m, n, 1000000007))

Submission status: Accepted

Solution code:
m,n = map(int,input().split());
a = pow(m, n,1000000007)
print(a);

Submission status: Accepted

Solution code:
def A(x):
    mod=1000000007
    return(x%mod)
    
def B(a,b,mod):
    if b==1:
        return a
    elif b%2==0:
        a_2=A(a**2)
        b_2=b//2
        return A(B(a_2,b_2,mod))
    else:
        a_2=A(a**2)
        b_2=(b-1)//2
        return A(B(a_2,b_2,mod)*a)
        
mod=1000000007
m,n=map(int,input().split())

print(B(m,n,mod))

Submission status: Accepted

Solution code:

m,n=map(int,input().split())
a=1000000007
print(pow(m,n,a))

Submission status: Accepted

Solution code:
m,n=map(int,input().split())
mod=1000000007
res=1
while n>0:
    if n & 1 == 1:
        res=res*m%mod
    m=m*m%mod
    n>>=1
print(res)

Submission status: Accepted

Solution code:
m,n = map(int, input().split())
print(pow(m, n, 1000000007))

Submission status: Accepted

Solution code:
n ,m=map(int,input().split())
print(pow(n,m,1000000007))

Submission status: Accepted

Solution code:
mod = 1000000007
l = input().split()
m = int(l[0])
n = int(l[1])


def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % mod
    elif y % 2 == 0:
        return power(x, y/2)**2 % mod
    else:
        return power(x, int(y/2))**2 * x % mod


ans = power(m, n)
print(ans)

Submission status: Accepted

Solution code:
m,n = map(int,input().split())
print(pow(m,n,1000000007))

Submission status: Accepted

Solution code:
m,n=map(int,input().split())

e=pow(m,n,1000000007)
print(e)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

M = 1000000007
def func(x, y):
   if y == 0:
      return 1
   elif y % 2 == 0:
      return func((x * x) % M, y / 2)
   else:
      return (x * func(x, y - 1) % M)

m, n = map(int, input().split())
print(func(m, n))

Submission status: Accepted

Solution code:
z=1000000007
x,y=map(int,input().split())
s=pow(x,y,z)
print(s)

Submission status: Accepted

Solution code:
m,n=map(int,input().split())

print(pow(m,n,1000000007))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())

MOD = 10**9 + 7

print(pow(n,m,MOD))

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

P = 10 ** 9 + 7


def main():
    M, N = map(int, input().split())

    ans = pow(M, N, P)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
m,n=map(int,input().split())

print(pow(m,n,10**9+7))

Submission status: Accepted

Solution code:
from functools import lru_cache
@lru_cache(maxsize=None)

def power(a, b):
    res = 1
    # print(a, b)
    if b > 0:
        res = power(a, b // 2)
        if b % 2 == 0:
            res = (res * res) % 1000000007
        else:
            res = (((res * res) % 1000000007) * a) % 1000000007
    
    return res
    
m, n = map(int, input().split())

print(power(m, n))

Submission status: Accepted

Solution code:
print(pow(*map(int, input().split()), 10**9+7))

Submission status: Accepted

Solution code:
m, n = map(int, input().split())

def mod_binary(base, exponent, modulo):
  mask = 1 << (exponent.bit_length() - 1)
  ans = 1
  while mask:
    ans = ans * ans % modulo
    if exponent & mask:
      ans = ans * base % modulo
    mask >>= 1
  return ans

print(mod_binary(m, n, 1000000007))

Submission status: Accepted

Solution code:
# 70

m, n = map(int, input().split())


def modpow(a, n, mod):
    ret = 1
    while n > 0:
        if n & 1:
            ret = ret * a % mod
        a = a * a % mod
        n >>= 1
    return ret


print(modpow(m, n, 10**9 + 7))

Submission status: Accepted

Solution code:
m,n = (int(x) for x in input().split())
print(pow(m,n,1000000007))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 標準入力を取得
m, n = list(map(int, input().split()))

# 求解処理
def modpow(a: int, b: int, mod: int) -> int:
    ans = 1
    while b > 0:
        if (b & 1):
            ans = ans * a % mod
        a = a * a % mod
        b >>= 1
    return ans

ans = modpow(m, n, 1000000007)

# 結果出力
print(ans)

Submission status: Accepted

Solution code:
m,n = (int(x) for x in input().split())
print(pow(m, n, 1000000007))

Submission status: Accepted

Solution code:
MOD = 10**9 + 7
a, b = list(map(int, input().split()))
print(pow(a, b, MOD))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

MOD = 1000000007
m, n = map(int,input().split())
print(pow(m, n, MOD))

Submission status: Accepted

Solution code:
kMod = 1000000007
m, n = map(int, input().split())

buf = {1:m}

i = 2

while i <= n:
    prev = buf[i // 2]
    cur = (prev * prev) % kMod
    buf[i] = cur
    i *= 2

ans = 1
i = 0
while (1 << i) <= n:
    if (1<<i) & n:
        ans *= buf[1<<i]
        ans %= kMod
    i += 1
print(ans)

Submission status: Accepted

Solution code:
m,n=map(int,input().split())
a=pow(m,n,1000000007)
print(a)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N, M = map(int, readline().split())
    ans = pow(N, M, MOD)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
m,n=map(int,input().split())
print(pow(m,n,1000000007))  #pow(x,y)でxのy乗　pow(x,y,z)でxのy乗をzで割った値

Submission status: Accepted

Solution code:
m,n = map(int, input().split())
ans = pow(m,n,10**9+7)

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
m,n=map(int,input().split())
p=pow(m,n,1000000007)
print(p)

Submission status: Accepted

Solution code:
def powmod(m, n, p):
    pow = m
    ret = 1
    while n > 0:
        if n & 1:
            ret = ret * pow % p
        pow = (pow * pow) % p
        n >>= 1
    return ret

m, n = [int(x) for x in input().split()]
p = 10 ** 9 + 7
print(powmod(m, n, p))

Submission status: Accepted

Solution code:
m, n= map(int, input().split())
p = 1000000007
a = pow(m, n, p)

print(a)

Submission status: Accepted

Solution code:
m, n = map(int, input().split())
N = pow(m, n, 1000000007)
print(N)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
print(pow(n,m,1000000007))

Submission status: Accepted

Solution code:
#74 べき乗

m,n = map(int, input().split())

mod = 1000000007

ans = pow(m, n, mod)    # mのn乗をmodで割った数　＝　pow関数

print(ans)

Submission status: Accepted

Solution code:
mod = 10**9+7
m, n =map(int, input().split())
print(pow(m,n,mod))

Submission status: Accepted

Solution code:
m, n = map(int, input().split())
print(pow(m, n, 10**9+7))

Submission status: Accepted

Solution code:
m,n = map(int,input().split())

print(pow(m,n, 1000000007))

Submission status: Accepted

Solution code:
m,n = map(int,input().split())
mod = 10**9+7
ans = pow(m,n,mod)
print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
d=1000000007

print(pow(n,m,d))

Submission status: Accepted

Solution code:
m,n=map(int,input().split())
print(pow(m,n,10**9+7))

Submission status: Accepted

Solution code:
# https://onlinejudge.u-aizu.ac.jp/problems/NTL_1_B

MOD = 10 ** 9 + 7
m, n = list(map(int, input().split()))
print(pow(m, n, MOD))

Submission status: Accepted

Solution code:
m, n = map(int, input().split())
print(pow(m, n, 10 ** 9 + 7))

Submission status: Accepted

Solution code:
def modpow(a, n, mod):
    res = 1
    while n > 0:
        if (n & 1):
            res = res * a % mod
        a = a * a % mod
        n = n >> 1

    return res


def main():
    m, n = map(int, input().split())
    print(modpow(m, n, 1000000007))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
m,n = map(int,input().split())

amari = pow(m,n,1000000007)

print(amari)

Submission status: Accepted

Solution code:
import math

m,n=map(int,input().split())
print(pow(m,n,1000000007))

Submission status: Accepted

Solution code:
m, n = map(int,input().split())
print(pow(m, n, 1000000007))

Submission status: Accepted

Solution code:
m,n = map(int,input().split())
a = 1000000007

def keisan(x, y):
    if y == 1:
        return x % a
    elif y % 2 == 0:
        return keisan(x, y/2)**2 % a
    else:
        return keisan(x, int(y/2))**2 * x % a

if n < 5:
    print(m**n)
else:
    ans = keisan(m, n)
    print(ans)

Submission status: Accepted

Solution code:
mod = 10**9+7
m, n = map(int, input().split())
print (pow(m,n,mod))

Submission status: Accepted

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

m,n = mi()

mod = 1000000007

def modpow(m,n,mod=1000000007):
    res = 1
    while n>0:
        if n&1: res = res * m % mod
        m = m * m % mod
        n >>= 1
    return res

ans = modpow(m,n)

print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split());print(pow(n,m,10**9+7))

Submission status: Accepted

Solution code:
m, n = map(int, input().split())
mod = 10**9 + 7


def modpow(m, n, mod):
    res = 1
    while n > 0:
        if n & 1:
            res = res * m % mod
        m = m * m % mod
        n >>= 1
    return res


print(modpow(m, n, mod))

Submission status: Accepted

Solution code:
m,n=map(int,input().split())
mod=1000000007

x=bin(n)[2:]
lst=[m for i in range(len(x))]
for i in range(1,len(x)):
    lst[i]=lst[i-1]**2
    lst[i]%=mod

sm=1
for i,b in enumerate(x):
    if b=="1":
        sm*=lst[len(x)-1-i]
        sm%=mod

print(sm)

Submission status: Accepted

Solution code:
m, n = map(int,input().split())
print(pow(m,n,1000000007))

Submission status: Accepted

Solution code:
m,n = map(int,input().split())
print(pow(m,n, 1000000007))

Submission status: Accepted

Solution code:
m, n = map(int, input().split())

print(pow(m, n, 10**9 + 7))

Submission status: Accepted

Solution code:
def modpow(a,n,m):
  res=1
  while n>0:
    if n&1:res=res*a%m
    a=a*a%m
    n//=2
  return res
INF=10**9+7
n,m=map(int,input().split())
print(modpow(n,m,INF))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    m, n = map(int, input().split())
    print(pow(m, n, mod))


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
def p(m, n, r=1000000007):
    return pow(m, n, r)


if __name__ == '__main__':
    m, n = list(map(int, input().split()))
    print(p(m, n))

Submission status: Accepted

Solution code:
m,n = map(int,input().split())
print(pow(m,n,10**9+7))

Submission status: Accepted

Solution code:
m, n = map(int, input().split())
mod = 10**9+7
print(pow(m, n, mod))

Submission status: Accepted

Solution code:
#(74)べき乗
import math
m,n=map(int,input().split())
print(pow(m,n,1000000007))

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
    
c=pow(a,b,1000000007)
    
print(c)

Submission status: Accepted

Solution code:
m,n=map(int, input().split())
k=1000000007

print(pow(m, n, k))

Submission status: Accepted

Solution code:
# coding: utf-8
# 74

m,n = map(int,input().split())

print(pow(m, n, 1000000007))

Submission status: Accepted

Solution code:
#NTL_1_B
m , n = map(int,input().split())
a = pow(m,n,1000000007)
print(a)

Submission status: Accepted

Solution code:
m,n=map(int,input().split())
print(pow(m, n, 1000000007))

Submission status: Accepted

Solution code:
import math
m, n = map(int,input().split())
x = pow(m, n, 1000000007)
print(x)

Submission status: Accepted

Solution code:
m, n = map(int, input().split())
print(pow(m, n, 1000000007))

Submission status: Accepted

Solution code:
m,n = list(map(int,input().split()))
print(pow(m,n,1000000007))

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
print(pow(a,b,1000000007))

Submission status: Accepted

Solution code:
def re(x, y):
    z = pow(x, y, 1000000007)
    print(z)
m, n = map(int,input().split())
re(m, n)

Submission status: Accepted

Solution code:
m,n=map(int,input().split())

div=10**9+7
def po(x,n,M):
    res=1
    if n>0:
        
        res= po(x,n//2,M)
    if n%2==0:
        res=(res*res)%M
    else:
        res=(((res*res)%M)*x)%M
        
      
    return res

print(po(m,n,div))

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

m, n = map(int, input().split())

MOD = 10 ** 9 + 7
def pow(a, b):
    c = 1
    while b > 1:
        if b % 2 == 0:
            b //= 2
            a *= a
        else:
            b -= 1
            c *= a
        a %= MOD
        c %= MOD
    return a * c
print(pow(m, n) % MOD)

Submission status: Accepted

Solution code:
def S(x) :
    mod = 1000000007
    return(x % mod)
    
def A(a, b, mod) :
    if b == 1 :
        return a
    elif b%2 == 0 :
        a_2 = S(a**2)
        b_2 = b // 2
        return S(A(a_2, b_2, mod))
    else :
        a_2 = S(a**2)
        b_2 = (b-1) // 2
        return S(A(a_2, b_2, mod)*a)
        
mod = 1000000007
m, n = map(int, input().split())

print(A(m, n, mod))

Submission status: Accepted

Solution code:
m,n = map(int,input().split())
MOD = 1000000007

def power(m,n):
    if n == 1:
        return m
    else:
        if n % 2 == 0:
            return (power(m,n//2)**2)%MOD
        else:
            return ((power(m,n//2)**2)*m)%MOD

print(power(m,n))

Submission status: Accepted

Solution code:
m, n = map(int, input().split())
mod = 10 ** 9 + 7


def my_pow(m, n, mod):
    # 繰り返し二乗法 偶数なら半分にして再帰でそれを返す、奇数ならmをかけてから
    if n == 1:
        return m
    if n % 2:
        return (m * my_pow(m, n // 2, mod) ** 2) % mod
    else:
        return (my_pow(m, n // 2, mod) ** 2) % mod


print(my_pow(m, n, mod))

Submission status: Accepted

Solution code:
m, n = map(int, input().split())
MOD = 1000000007
print(pow(m, n, MOD))

Submission status: Accepted

Solution code:
m, n = map(int, input().split())

mod = 10 ** 9 + 7


def modpow(m, n, mod):
    if n == 0:
        return 1

    if n % 2 == 0:
        return modpow(m, n // 2, mod) ** 2 % mod
    else:
        return modpow(m, n - 1, mod) * m % mod


print(modpow(m, n, mod) % mod)

Submission status: Accepted

Solution code:
m,n=map(int,input().split())
p=pow(m,n,1000000007)
print(p)

Submission status: Accepted

Solution code:
MOD=pow(10, 9)+7

def main():
    m, n = map(int, input().split())
    ans = pow(m, n, MOD)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

m,n = map(int, input().split())

def my_pow(m,n):
    res = 1
    while n > 0:
        if n&1:
            res = res * m
        m = m * m
        n >>= 1
    return res

def my_pow_mod(m,n,M):
    res = 1
    while n > 0:
        if n&1:
            res = res * m % M
        m = m * m % M
        n >>= 1
    return res

print(my_pow_mod(m,n,1000000007))

Submission status: Accepted

Solution code:
m, n = map(int, input().split())
inf = 1000000007

a = [m]
for i in range(30):
    m *= m
    m %= inf
    a.append(m)

ans = 1
i = 0
while(n>0):
    if n%2 == 1:
        ans *= a[i]
        ans %= inf
    n = n//2
    i += 1
    
print(ans)

Submission status: Accepted

Solution code:
def main():
    import sys
    M, N = map(int, sys.stdin.readline().split())
    mod = 10**9+7
    
    # a**b
    def calc(a,b, mod):
        if b==1:
            return a % mod
        if b %2==0:
            return calc(a**2%mod, b//2, mod) % mod
        elif b % 2==1:
            return a*calc(a, b-1, mod) % mod
            
    
    ans = calc(M, N, mod)
    print(ans)
    #確認
    #print(pow(M, N, mod))
    
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:

m,n =  map(int,input().split())
print(pow(m,n,1000000007))

Submission status: Accepted

Solution code:
m,n = map(int,input().split())
print(pow(m, n, 10**9+7))

Submission status: Accepted

Solution code:
m, n = map(int,input().split())
ans = pow(m,n,10**9+7)
print(ans)

Submission status: Accepted

Solution code:
def cal_expo(m, n, MOD):
    if m == 1:
        return 1
    ans = 1
    while n != 1:
        if n % 2 != 0:
            ans = (ans * m) % MOD
        n //= 2
        m = (m ** 2) % MOD
    ans = (ans * m) % MOD
    return ans


def main():
    m, n = map(int, input().split())
    MOD = 10 ** 9 + 7
    ans = cal_expo(m, n, MOD)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
m, n = map(int, input().split())
print(pow(m, n, 10**9 + 7))

Submission status: Accepted

Solution code:
m,n=map(int,input().split())

ans = pow(m,n,1000000007)


print(ans)

Submission status: Accepted

Solution code:
def mod_pow(a, n, mod):
    """
    二分累乗法による a^n (mod m)の実装
    :param a: 累乗の底
    :param n: 累乗の指数
    :param mod: 法
    :return: a^n (mod m)
    """

    result = 1
    a_n = a
    while n > 0:
        if n & 1:
            result = result * a_n % mod
        a_n = a_n * a_n % mod
        n >>= 1
    return result


MOD = 1000000007

M, N = map(int, input().split(' '))

print(mod_pow(M, N, MOD))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

M = 1000000007
def func(x, y):
   if y == 0:
      return 1
   elif y % 2 == 0:
      return func((x * x) % M, y / 2)
   else:
      return (x * func(x, y - 1) % M)

m, n = map(int, input().split())
print(func(m, n))

Submission status: Accepted

Solution code:
print(pow(*list(map(int,input().split())),10**9+7))

Submission status: Accepted

Solution code:
M, N = map(int, input().split())
mod = 1000000007

def modpow(a, n, mod):
  res = 1
  while (n > 0):
    if (n & 1):
      res = res * a % mod
    a = a * a % mod
    n >>= 1
  return res


print(modpow(M, N, mod))

Submission status: Accepted

Solution code:
m, n = map(int, input().split())

ans = pow(m, n, 1000000007)

print(ans)

Submission status: Accepted

Solution code:
p = 1000000007
def modPow(a, n, m):
    ans = 1
    while n > 0:
        if (n & 1): ans = (ans * a) % m
        a = (a * a) % m
        n = n >> 1
    return ans

n, m = map(int, input().split())
print(modPow(n, m, p))

Submission status: Accepted

Solution code:
m, n = [int(arg) for arg in input().split()]
print(pow(m, n, 1000000007))

Submission status: Accepted

Solution code:
mod = 10**9+7

m, n = map(int,input().split())

ans = pow(m,n,mod)
print(ans)

Submission status: Accepted

Solution code:
#標準入力
a,b = map(int,input().split())

#aのb乗を1,000,000,007で割った余りを出力する
print(pow(a,b,1000000007))

Submission status: Accepted

Solution code:
m, n = map(int, input().split())
x = 1000000007
print(pow(m,n,x))

Submission status: Accepted

Solution code:
x = 1000000007
m,n=map(int,input().split())
print(pow(m,n,x))

Submission status: Accepted

Solution code:

m, n = map(int, input().split())

mod = 10**9 + 7

res = pow(m, n, mod)

print(res)

Submission status: Accepted

Solution code:
def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else            : return power(x, y//2)**2 * x % mod

m,n=map(int,input().split())

mod=10**9+7

print(power(m,n))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
print(pow(n,m,1000000007))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
INF = float('inf')

MOD = 1000000007
m, n = map(int, input().split())


def pow_fast(m, n):
    if n == 0:
        return 1
    elif n % 2 == 0:
        return pow_fast(m * m % MOD, n / 2)
    else:
        return pow_fast(m * m % MOD, int(n / 2)) * m % MOD


print(pow_fast(m, n))

Submission status: Accepted

Solution code:
m, n = map(int, input().split())
print(pow(m,n,10**9+7))

Submission status: Accepted

Solution code:
mod = 10**9 + 7

def pow(x, y):
    ret = 1
    while y:
        if y & 1:
            ret = ret * x % mod
        x = x * x % mod
        y >>= 1
    
    return ret

m, n = map(int, input().split())
print(pow(m, n))

Submission status: Accepted

Solution code:
def pow(a, n, MOD=1):
    """
    繰り返し二乗法 (半分の数の 2 乗) / 自乗
    Compute nth power of a -- O(logn)
    """
    if n == 0:
        return 1
    x = pow(a, n//2, MOD)
    x = (x%MOD * x%MOD) % MOD
    if n%2 == 1:
        x = (x%MOD * a%MOD) % MOD
    return x


MOD = 1_000_000_007
m, n = map(int, input().split())
print(pow(m, n, MOD))

Submission status: Accepted

Solution code:
m,n=map(int,input().split())
p=pow(m,n,1000000007)
print(p)

Submission status: Accepted

Solution code:
import math

def power2(n):
  global ans
  if n == 1:
    tmp =  m % p
  elif n % 2 == 0:
    tmp = power2(n//2) ** 2 % p
  else:
    tmp =  power2(n//2) * power2((n+1)//2) % p
  return ans * tmp % p
    
m, n = map(int, input().split())
p = 10**9+7
ans = 1
print(power2(n))

Submission status: Accepted

Solution code:
a,x = map(int, input().split())
n = 1000000007
print(pow(a, x, n))

Submission status: Accepted

Solution code:
m, n = map(int, input().split())
mod = 1000000007

print(pow(m, n, mod))

Submission status: Accepted

Solution code:
m, n = map(int, input().split())
mod = 1000000007
print(pow(m, n, mod))

Submission status: Accepted

Solution code:
import sys, collections
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
MOD = 1000000007
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    m, n = LI()

    # print(pow(m, n, MOD))
    def f(m, n, p):
        if n==1:
            return m
        else:
            if n%2==0:
                return (f(m, n//2, p)**2) % p
            else:
                return (f(m, n//2, p)**2*m) % p
    print(f(m, n, MOD))

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:

M,N = map(int,input().split())
mod = 10**9+7
print(pow(M, N, mod))

Submission status: Accepted

Solution code:
m,n=map(int,input().split())
#print((m**n)%1000000007)
print(pow(m,n,1000000007))

Submission status: Accepted

Solution code:
m,n = map(int,input().split())
MOD = 10**9+7
a = pow(m,n,MOD)
print(a)

Submission status: Accepted

Solution code:
# NTL_1_B: Power
import sys
m, n = map(int, sys.stdin.readline().strip().split())

mod = 10**9 + 7

print(pow(m, n, mod))

Submission status: Accepted

Solution code:
# import sys
import math

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
# INF = sys.maxsize

# ===CODE===

m, n = map(int, input().split())

res = 1
mod = 10 ** 9 + 7
while n > 0:
    if n & 1 == 1:
        res = res * m % mod
    m = m * m % mod

    n >>= 1

print(res)

Submission status: Accepted

Solution code:
import sys,bisect,math
sys.setrecursionlimit(15000)

M,N = map(int,sys.stdin.readline().split())

def powmod(m,n,mod):
  if n == 1:
    return m
  ret = (powmod(m*m%mod,n//2,mod))%mod
  if n%2==1:
    return (ret*m)%mod
  return ret%mod

print(powmod(M,N,1000000007))

Submission status: Accepted

Solution code:
import sys

m, n = map(int, sys.stdin.readline().strip().split())
print(pow(m, n, 10**9 + 7))

Submission status: Accepted

Solution code:
mod = 10**9+7
def power(m, n):
    if n == 0:
        return 1
    res = power(m*m%mod, n//2)
    if n%2 == 1:
        res = res*m%mod
    return res

m, n = map(int, input().split())
print(power(m, n))

Submission status: Accepted

Solution code:
m, n = map(int, input().split())
MOD = 10 ** 9 + 7
print(pow(m, n, MOD))

Submission status: Accepted

Solution code:
m, n = map(int, input().split())
mod = 10**9 + 7
print(pow(m, n, mod))

Submission status: Accepted

Solution code:
m,n = map(int,input().split())
mod = 10**9+7
# print(pow(m,n,mod))

def power(x,n,m):
    res = 1
    if n > 0:
        res = power(x,n//2,m)
        if n%2 == 0: res = res*res%m
        else: res = res*res%mod*x%m
    return res

print(power(m,n,mod))

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    m,n = map(int, readline().split())

    MOD = 10**9+7
    print(pow(m, n, MOD))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
m,n = list(map(int, input().split()))

def mod_pow(a,n,mod):
    ret = 1
    while n>0:
        if (n & 1): ret = ret * a % mod
        a = a * a % mod
        n >>= 1
    return ret

print(mod_pow(m,n,10**9+7))

Submission status: Accepted

Solution code:
MOD = 10**9+7
def pow(a, b):
    res = 1
    while b:
        if b & 1: res = res * a % MOD
        a = a**2 % MOD
        b >>= 1
    return res
    
m, n = list(map(int, input().split()))
print(pow(m, n))

Submission status: Accepted

Solution code:
MOD = 1_000_000_007
m, n = map(int, input().split())

def modpower_rec(a, b, M=MOD):
    # compute a^b (mod M)
    if b <= 8:
        return (a ** b) % M
    else:
        if b % 2 == 0:
            return modpower_rec(a ** 2, b // 2, M)
        else:
            return (modpower_rec(a ** 2, b // 2, M) * a) % M


def modpower_rec2(a, b, M=MOD):
    if b == 0:
        return 1
    elif b % 2 == 0:
        return modpower_rec2((a ** 2) % M, b // 2) % M
    else:
        return (modpower_rec2((a ** 2) % M, b // 2) * a) % M


def mpower(a, b, M=MOD):
    rem = 1
    while b > 0:
        if b % 2 == 1:
            rem = rem * a % M
        a = a ** 2 % M
        b //= 2
    return rem % M

# print(modpower_rec(m, n, MOD))
# print(modpower_rec2(m, n, MOD))
print(mpower(m, n, MOD))

Submission status: Accepted

Solution code:
m, n = map(int, input().split())
print(pow(m, n, 10**9+7))

Submission status: Accepted

Solution code:
MOD=1000000007

def log_n_power(m,n,mod):
    if n==0:
        return 1
    elif n%2:
        k=log_n_power(m,n//2,mod)
        return k*k*m%mod
    else:
        k=log_n_power(m,n//2,mod)
        return k*k%mod

def main():
    m,n=map(int,input().split())
    print(log_n_power(m,n,MOD))

main()

Submission status: Accepted

Solution code:
def modpow(a,n,mod):
    res=1
    a=a%mod
    while(n>0):
        if(n&1):
            res=res*a%mod
        a=a*a%mod
        n>>=1
    return res

m,n=map(int,input().split())
print(modpow(m,n,10**9+7))

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7
m,n = map(int,input().split())

def pow_k(x, n):
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K = K * x % MOD
        x = x ** 2 % MOD
        n //= 2

    return K * x % MOD

print(pow_k(m,n))

Submission status: Accepted

Solution code:
m,n = map(int,input().split())
mod = 10 ** 9 + 7

result = pow(m,n,mod)
print(result)

Submission status: Accepted

Solution code:
def pow_k(x, n, M):

    if n == 0:
        return 1

    K = 1
    while n:
        if n & 1:
            K *= x
            K %= M
        x *= x
        x %= M
        n >>= 1

    return K

M = 1000000007
m, n = map(int, input().split())
print(pow_k(m, n, M))

Submission status: Accepted

Solution code:
m,n=map(int, input().split())
MOD=10**9+7
ans = 1
t = m
while n:
    if n&1: ans = (ans*t)%MOD
    n >>= 1
    t = (t*t)%MOD
print(ans)

Submission status: Accepted

Solution code:
m, n = map(int, input().split())

P = 10 ** 9 + 7

# 繰り返し二乗法
def pow(x, n, p):
  r = 1
  while n > 0:
    if n & 1:
      r = (r * x) % p
    x = (x * x) % p
    n >>= 1
  return r

print(pow(m, n, P))

Submission status: Accepted

Solution code:
m,n=map(int,input().split())
mod=10**9+7
print(pow(m,n,mod))

Submission status: Accepted

Solution code:
m, n = map(int, input().split())
mod = 10 ** 9 + 7
ans = pow(m, n, mod)
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


def p(M, N, mod):
    if N == 0:
        return 1
    if N % 2 == 0:
        half = p(M, N // 2, mod)
        return half * half % mod
    else:
        return M * p(M, N - 1, mod) % mod


if __name__ == "__main__":
    M, N = map(int, input().split())
    mod = 1_000_000_007
    ans = p(M, N, mod)
    print(ans)

Submission status: Accepted

Solution code:
def mod_pow(m, n, mod):
    if n == 0:
        return 1
    if n == 1:
        return m % mod

    res = 1
    if n % 2 == 1:
        res = res * m

    return (res * (mod_pow((m * m) % mod, n // 2, mod)) % mod) % mod


mod = 10 ** 9 + 7
m, n = map(int, input().split())
print(mod_pow(m, n, mod))

Submission status: Accepted

Solution code:
m,n=map(int,input().split())
mod=10**9+7
print(pow(m,n,mod))

Submission status: Accepted

Solution code:
def rep_pow(a, k, p=10**9+7):
    # calculate exponentiation: a^k mod p
    ans = 1
    while k > 0:
        if k & 1:
            ans = ans * a % p
        a = a * a % p
        k >>= 1
    return ans

m, n = map(int, input().split())
print(rep_pow(m, n))