Answers for "a ^ b java"

0

a ^ b java

/*
  Given two non-negative integers a and b. Let's calculate a^b.
  If the result is too large, divide the remainder by 10^9 + 7.
*/
import java.util.Scanner;

public class EXC {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long res = 1;
        long mod = (long)1e9 + 7;
        while(b > 0){
          if ( b % 2 != 0) res = res * a % mod;
          a = a * a % mod;
          b >>= 1;
        }
        System.out.println(res);
    }
}
Posted by: Guest on October-13-2021

Code answers related to "a ^ b java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language