Last active
September 18, 2018 17:39
-
-
Save kupp1/6b01fe9191b0982a16bf25e34ee89b9d to your computer and use it in GitHub Desktop.
UniLecs #127. Интервальная сумма
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Задача: даны два натуральных числа a, b. Необходимо найти сумму чисел на интервале [a, b] (включая концы интервала). | |
| Входные данные: a, b, где a <= b. a, b от 1 до 10^9. | |
| Вывод: sum - сумма чисел на интервале [a, b]. | |
| Пример: a = 1, b = 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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