解题思路:
绝对值的问题,既然O是固定的,直接传入值考虑乘以二减一的思路,考虑到数值越界,使用BigInteger作为数据类型,因为A值可能为0或为负数,所以加上判断,如果A为0或为负,则直接输出0,否则输出O*2-1的值。
代码实现:
import java.math.BigInteger;
import java.util.Scanner;
public class p6581 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
BigInteger a= sc.nextBigInteger();
BigInteger b = BigInteger.valueOf(0);
BigInteger c = BigInteger.valueOf(2);
int d = a.compareTo(BigInteger.valueOf(0));
if (!(d>0)) {
System.out.println(0);return;
}
System.out.println(a.multiply(c).subtract(BigInteger.valueOf(1)));
}
}