Skip to content

Instantly share code, notes, and snippets.

@kupp1
Last active September 18, 2018 17:39
Show Gist options
  • Select an option

  • Save kupp1/6b01fe9191b0982a16bf25e34ee89b9d to your computer and use it in GitHub Desktop.

Select an option

Save kupp1/6b01fe9191b0982a16bf25e34ee89b9d to your computer and use it in GitHub Desktop.
UniLecs #127. Интервальная сумма
Задача: даны два натуральных числа a, b. Необходимо найти сумму чисел на интервале [a, b] (включая концы интервала).
Входные данные: a, b, где a <= b. a, b от 1 до 10^9.
Вывод: sum - сумма чисел на интервале [a, b].
Пример: a = 1, b = 3
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
int main(int argc, char const *argv[]) {
uintmax_t a = atoi(argv[1]);
uintmax_t b = atoi(argv[2]);
uintmax_t tmp = (a + b) * (b - a + 1) * 0.5;
//арифмитическая прогрессия
printf("%ju\n", tmp);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment