Все задачи
Легко Решено: 0 Процент решений: 0%

Difference of Squares

Subtract the sum of squares from the square of the sum.

Using the integers from 1 through n, calculate two quantities: first add the integers and square the result; separately square each integer and add those squares. Return the first quantity minus the second.

Implement difference_of_squares(n).

Input

n: The last integer to include.

Output

Return square-of-sum minus sum-of-squares.

Ограничения

0 ≤ n ≤ 50,000. For n = 0, both sums are 0. All required values fit signed 64-bit integers.

Примеры

Пример 1
Ввод:
n = 4

Ожидаемый вывод:
expected = 70
Ввод:
long long n = 4;

Ожидаемый вывод:
long long expected = 70;
Ввод:
long n = 4;

Ожидаемый вывод:
long expected = 70;

Пояснение

(1 + 2 + 3 + 4)² = 100. The sum of squares is 1 + 4 + 9 + 16 = 30. Subtract: 100 − 30 = 70.

Пример 2
Ввод:
n = 1

Ожидаемый вывод:
expected = 0
Ввод:
long long n = 1;

Ожидаемый вывод:
long long expected = 0;
Ввод:
long n = 1;

Ожидаемый вывод:
long expected = 0;

Пояснение

Both quantities equal 1, so their difference is 0.

Ссылки

Это задание адаптировано для CodeUtility. Следуйте условию и ограничениям выше.

Учитесь у других

Решения сообщества

Пока нет опубликованных решений. Решите задание, чтобы поделиться первым.