FastIO

Java也有输入输出外挂 XD
不过判断EOF比较蹩脚

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.io.*;
import java.util.*;
import java.math.*;

class Main{

static class Reader{
static BufferedReader reader;
static StringTokenizer tokenizer;

static void init(InputStream input){
reader=new BufferedReader(new InputStreamReader(input));
tokenizer= new StringTokenizer("");
}

static String next() throws IOException {
String s;
while(!tokenizer.hasMoreTokens()){
if((s=reader.readLine())==null) return null;
tokenizer = new StringTokenizer(s);
}
return tokenizer.nextToken();
}

static Integer nextInt() throws IOException {
String s=next();
if(s==null) return null;
return Integer.parseInt(s);
}

static Double nextDouble() throws IOException {
String s=next();
if (s==null) return null;
return Double.parseDouble(s);
}
}

public static void main(String[] args) {
//InputStream f=new FileInputStream("/home/alex/Desktop/test.txt");
//Reader.init(f);
Reader.init(System.in);
PrintWriter Writer = new PrintWriter(System.out);
//Scanner in= new Scanner(System.in);
try{
BigDecimal R;
int n;
while(true){
String s=Reader.next();
if(s==null) break;
R=new BigDecimal(s);
R=R.stripTrailingZeros(); //丢弃尾部0
//System.out.println(R.toString());
n=Reader.nextInt();
R=R.pow(n);
String S=R.toPlainString(); //非科学表示
if(S.charAt(0)=='0') S=S.substring(1,S.length());
Writer.println(S);
}
} catch (IOException e){
} finally {
Writer.close();
}
}
}

大数

BigInteger

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.io.*;
import java.util.*;
import java.math.BigInteger; // Load in

public class Main{

public static void main(String[] argc){
BigInteger a,b,c;
String s;
int cmp,i;
long l;
boolean flag;

Scanner in=new Scanner(System.in); //input
while(in.hasNext()){
a=in.nextBigInteger();
b=in.nextBigInteger();
}
System.out.println(c); //output

c=new BigInteger("1"); // 1
c=c.valueOf(1);
i=c.intValue(); // 1
l=c.longValue(); // 1
s=c.toString(); // "1"
s=c.toString(k); // k进制

cmp=a.compareTo(b); // -1 < 0 = 1 >
c=a.max(b); // max(a,b)
c=a.min(b); // min(a,b)

c=c.negate(); // -c
cmp=c.signum(); // -1 -> - 0 -> 0 1 -> +

c=a.add(b);
c=a.subtrac(b);
c=a.multiply(b)
c=a.divide(b);
c=a.mod(b) //or c=a.remainder(b); //+ - * / %
c=a.pow(k); //^k

//bit operator
c=a.and(b);
c=a.or(b);
c=a.xor(b);
c=a.not();
c=a.shiftLeft(1);
c=a.shiftRight(1);

flag=a.isProbablePrime(n); // 1-1/n^2 possible
c=a.nextProbablePrime(); //
c=a.modInverse(b); // a^-1 mod c
c=a.modPow(b,c); // a^b mod c

}
}

BigDecimal

特殊用法见FastIO部分