Click Here to go back to the homepage.

Sum Kind of Problem Solution:


import java.util.Scanner;
import java.util.stream.IntStream;

public class Kattis {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int cases = 1 + sc.nextInt();
    for (int i = 1; i < cases; i++) {
      sc.nextInt();
      int n = sc.nextInt();
      int odds = IntStream.rangeClosed(1, n).map(x -> 2*x).sum();
      System.out.printf("%d %d %d %d%n", i, IntStream.rangeClosed(1, n).sum(), odds - n, odds);
    }
  }
}