forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathD.java
More file actions
38 lines (32 loc) · 1.2 KB
/
D.java
File metadata and controls
38 lines (32 loc) · 1.2 KB
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
import java.io.File;
import java.io.PrintWriter;
import java.lang.Exception;
import java.lang.System;
import java.util.Scanner;
import java.math.BigInteger;
public class D {
public static void main(String[] args) {
try {
Scanner sc = new Scanner(new File("digit.in"));
BigInteger a = new BigInteger(sc.next());
String binaryValue = a.toString(2);
int n = binaryValue.length();
BigInteger[][] f = new BigInteger[500][2];
for (int i = 0; i <= n; i++)
for (int j = 0; j < 2; j++)
f[i][j] = BigInteger.ZERO;
f[n][0] = BigInteger.ONE;
for (int i = n - 1; i >= 0; i--)
for (int j = 0; j < 2; j++) {
int bit = binaryValue.charAt(i) - '0' - j;
for (int k = 0; k < 2; k++)
if (bit + k * 2 >= 0 && bit + k * 2 <= 2)
f[i][k] = f[i][k].add(f[i + 1][j]);
}
PrintWriter pw = new PrintWriter(new File("digit.out"));
pw.println(f[0][0]);
pw.close();
} catch (Exception e) {
}
}
}