erfanul007

UVa 1647

Apr 19th, 2021
577
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×