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);
    }
}
BreadCode