Skip to content

Instantly share code, notes, and snippets.

@unilecs
Created September 16, 2018 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unilecs/38d795778ee78e35f3efb775496c02ab to your computer and use it in GitHub Desktop.
Save unilecs/38d795778ee78e35f3efb775496c02ab to your computer and use it in GitHub Desktop.
Задача 127: Интервальная сумма
using System;
public class Program
{
public static long SumOfRange(long a, long b)
{
long result = (a + b) * (b - a + 1) / 2;
return result;
}
public static void Main()
{
Console.WriteLine("UniLecs");
Console.WriteLine(string.Format("Answer = {0}", SumOfRange(1, 2))); // 3
Console.WriteLine(string.Format("Answer = {0}", SumOfRange(1, 3))); // 6
Console.WriteLine(string.Format("Answer = {0}", SumOfRange(2, 4))); // 9
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment