Advertisement
erfanul007

UVa 1647

Apr 19th, 2021
905
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. import java.math.BigInteger;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.     public static void main(String[] args) {
  6.  
  7.         BigInteger[] arr = new BigInteger[1001];
  8.         arr[1] = BigInteger.valueOf(0);
  9.         arr[2] = BigInteger.valueOf(1);
  10.         for(int i=3; i < 1001; i++){
  11.             arr[i] = arr[i-1].multiply(BigInteger.valueOf(2));
  12.             if(i % 2 == 0){
  13.                 arr[i] = arr[i].add(BigInteger.valueOf(1));
  14.             }
  15.             else{
  16.                 arr[i] = arr[i].subtract(BigInteger.valueOf(1));
  17.             }
  18.         }
  19.  
  20.         Scanner in = new Scanner(System.in);
  21.  
  22.         while(in.hasNext()){
  23.             int b;
  24.             b = in.nextInt();
  25.             System.out.println(arr[b]);
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement