zcmu Problem A: a^b-b^a

【题目】

Problem A: a^b-b^a

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 470  Solved: 98
[Submit][Status][Web Board]

Description

计算a^b-b^a的值

Input

第一行一个整数T,表示接下来有T行

每行两个整数a和b,(0<a,b<1000)

Output

输出值

Sample Input

3
1 1
2 1
10 9

Sample Output

0
1
-2486784401

【...】

明天研究一下Java大整数运算吧我一无所知...

【代码】

import java.math.BigInteger; 
import java.util.Scanner;   
import java.text.*;    
public class Main{   
    public static void main(String[] args){   
        Scanner cin = new Scanner(System.in);   
        int n = cin.nextInt(); 
        int a, b;   
        for (int i=0;i<n;i++) 
        { 
            while(cin.hasNext())
            {   
                a=cin.nextInt();   
                b=cin.nextInt();   
                System.out.println(BigInteger.valueOf(a).pow(b).add(BigInteger.valueOf(b).pow(a).negate()));
            } 
        }   
    } 
} 

猜你喜欢

转载自blog.csdn.net/qq_41117236/article/details/81122535