112. ab-ba
time limit per test: 0.25 sec.
memory limit per test: 4096 KB
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
用scanner 会TLE
import java.io.*;
import java.math.BigInteger;
public class Main {
public static void main(String args[]) throws IOException {
StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
BigInteger a;
BigInteger b;
in.nextToken();
int A=(int) in.nval;
in.nextToken();
int B=(int) in.nval;
a=BigInteger.valueOf(A);
b=BigInteger.valueOf(B);
out.println(a.pow(B).subtract(b.pow(A)));
out.flush();
}
}
多组
while (in.nextToken() != StreamTokenizer.TT_EOF)
我ruby A的姿势好丑,想学ruby啊太菜了
a=gets.split
x=a[0].to_i
y=a[1].to_i
print x**y-y**x