A. Permutation Warm-Up
Source: codeforces
Tags: combinatorics, greedy, math

For a permutation $p$ of length $n$^{\text{∗}}$, we define the function:
You are given a number $n$. You need to compute how many distinct values the function $f(p)$ can take when considering all possible permutations of the numbers from $1$ to $n$.
$^{\text{∗}}$A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array).

-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). The description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \leq n \leq 500$) — the number of numbers in the permutations.

-----Output-----
For each test case, output a single integer — the number of distinct values of the function $f(p)$ for the given length of permutations.

-----Examples-----
Input:
5
2
3
8
15
43
Output:
2
3
17
57
463

-----Note-----
Consider the first two examples of the input.
For $n = 2$, there are only $2$ permutations — $[1, 2]$ and $[2, 1]$. $f([1, 2]) = \lvert 1 - 1 \rvert + \lvert 2 - 2 \rvert = 0$, $f([2, 1]) = \lvert 2 - 1 \rvert + \lvert 1 - 2 \rvert = 1 + 1 = 2$. Thus, the function takes $2$ distinct values.
For $n=3$, there are already $6$ permutations: $[1, 2, 3]$, $[1, 3, 2]$, $[2, 1, 3]$, $[2, 3, 1]$, $[3, 1, 2]$, $[3, 2, 1]$, the function values of which will be $0, 2, 2, 4, 4$, and $4$ respectively, meaning there are a total of $3$ values.

C++ solution:
#include <iostream>
using namespace std;

int main() {
    // Optimize input/output operations
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    
    while (t--) {
        int n;
        cin >> n;
        
        // Calculate the number of distinct values
        // Using long long to prevent potential integer overflow
        long long result = 1 + (n * n) / 4;
        
        cout << result << '\n';
    }
    
    return 0;
}

Go solution:
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	// Read number of test cases
	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())

	// Process each test case
	for i := 0; i < t; i++ {
		scanner.Scan()
		n, _ := strconv.Atoi(scanner.Text())
		result := 1 + (n * n) / 4
		fmt.Fprintln(writer, result)
	}
}

Java solution:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        
        for (int i = 0; i < t; i++) {
            int n = scanner.nextInt();
            System.out.println(1 + n * n / 4);
        }
        
        scanner.close();
    }
}

JavaScript solution:
const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let input = [];
let currentLine = 0;

rl.on('line', (line) => {
    input.push(line.trim());
});

rl.on('close', () => {
    const t = parseInt(input[0], 10);
    for (let i = 1; i <= t; i++) {
        const n = parseInt(input[i], 10);
        if (n < 1 || n > 500) {
            console.error("n must be between 1 and 500");
            process.exit(1);
        }
        const result = 1 + Math.floor(n * n / 4);
        console.log(result);
    }
});

Python solution:
t=int(input())
for _ in range(t):
    n=int(input())
    print((n*n)//4+1)

Ruby solution:
# Read the number of test cases
t = gets.to_i

# Process each test case
t.times do
  # Read the value of n for the current test case
  n = gets.to_i

  # Calculate the number of distinct function values
  result = 1 + (n * n) / 4

  # Output the result
  puts result
end