code.ashish.me

Atom feed

Recently added: 02 Count Of Subset Sum, 416 Partition Equal Subset Sum, 01 Subset Sum, 518 Coin Change 2, 983 Minimum Cost For Tickets

Missingnumber

import java.util.*;
import java.io.*;

/**
 *
 * Ashish Patel
 * e: ashishsushilPatel@gmail.com
 * w: https://ashish.me
 *
 */

class MissingNumber {

  static PrintWriter pw;
  static BufferedReader br;
  static StringTokenizer st;

  static long nl() {
    return Long.parseLong(st.nextToken());
  }

  static int ni() {
    return Integer.parseInt(st.nextToken());
  }

  public static void main(String[] args) throws IOException {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(System.out);
    st = new StringTokenizer(br.readLine());
    long t = ni();
    st = new StringTokenizer(br.readLine());
    long actualSum = 0;
    for (int i = 0; i + 1 < t; ++i) {
      actualSum += nl();
    }
    long totalSum = (t * (t + 1))/2;
    pw.print(totalSum-actualSum);
    br.close();
    pw.close();
  }
}

Created 2021-12-31T07:44:54+00:00, updated 2021-12-31T08:22:17+00:00 · History · Edit