Under construction

Still being built. Things may change

Can You Exponentiate?

Time limit1sMemory limit128 MB

Summary
Given a and b up to 1e9, print the last decimal digit of a^b.
Level

Easy3 of 10

Topics
Math, Number theory, Bit manipulation
Solved
No attempts yet

Problem

Given two natural numbers aa and bb, find the last (least significant) digit of aba^b.

Write a program that:

  • reads the base aa and the exponent bb,
  • computes the last digit of aba^b,
  • prints the result.

Input

The first and only line contains two integers aa and bb separated by a single space (1≤a,b≤1091 \le a, b \le 10^{9}).

Output

Print only the last (least significant) digit of aba^b written in decimal.

Examples1

  1. Example 1

    Input
    2 3
    
    Expected output
    8