ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1068. Sum

Where is error? 1068
Posted by Ogurechnicov 18 Sep 2013 00:08
using System;

    class Program
    {
        static void Main()
        {
            int a = 1;
            int N;
            N = int.Parse(Console.ReadLine());
            if(Math.Abs(N)<10000)
                 if (N >= 1)
                    Console.WriteLine(((a + N) / 2) * N);
                 else
                    Console.WriteLine(((a+Math.Abs(N)) / 2) * N+1);
            else
            Console.WriteLine("ERROR");
          }
}

Edited by author 18.09.2013 00:10

Edited by author 18.09.2013 00:12
Re: Where is error? 1068
Posted by LearningPython 18 Sep 2013 01:31
what if the output is N=2

(a+N)/2=1.5  1.5*2=3.0 this is not an integer

better: (N+1)*N div 2

if N<0:
   -((N+1)*N div 2) + 1