SGU112-a^b-b^a (BigNum)

You are given natural numbers a and b. Find ab-ba.

Input

Input contains numbers a and b (1≤a,b≤100).

Output

Write answer to output. 

Sample Input

2 3

Sample Output

-1

 

分析:

BigNum問題,這類問題很基礎,雖然有模板,但是還是自己記住爲好,以後碰到面試肯定不會讓你帶着模板去。

 

import java.math.BigInteger;
import java.util.Scanner;
public class Solution
{
    public static void main(String[] args)
    {
        Scanner cin = new Scanner(System.in);
        int a, b;
        while(cin.hasNext())
        {
            a = cin.nextInt();
            b = cin.nextInt();
            System.out.println(BigInteger.valueOf(a).pow(b).add(BigInteger.valueOf(b).pow(a).negate()));
        }
    }
}


 

 

 

C/C++版本待補充

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章