#C2448. Sum of Multiples

    ID: 45765 Type: Default 1000ms 256MiB

Sum of Multiples

Sum of Multiples

Given an integer n, find the sum of all integers from 1 to n (inclusive) that are divisible by either 3 or 5. For example, if n = 10, the numbers 3, 5, 6, and 9 are counted, and their sum is 33.

The problem requires you to process multiple test cases. The first input line contains an integer T specifying the number of test cases. Each of the next T lines contains a single integer n. For each test case, output the sum of all integers from 1 to n (inclusive) that are divisible by 3 or 5 on a separate line.

Mathematically, for a given n, you are to compute:

\( S(n)=\sum_{i=1}^{n} \mathbf{1}_{(i\,\%\,3==0 \; \text{or} \; i\,\%\,5==0)} \cdot i \)

This is a straightforward simulation problem that can be solved by iterating from 1 to n and checking divisibility conditions.

inputFormat

The first line contains an integer T (the number of test cases). The following T lines each contain one integer n (where 1 ≤ n ≤ 106).

outputFormat

For each test case, print the sum of all numbers from 1 to n that are divisible by 3 or 5, each on a new line.

## sample
5
10
20
5
3
1
33

98 8 3 0

</p>