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

Solution in Java
Posted by xukien 2 Nov 2012 13:44
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;


public class No1068 {
    public static void main(String[] args) throws Exception {
        BufferedReader rd=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter wr=new PrintWriter(new OutputStreamWriter(System.out));
        StringTokenizer line =new StringTokenizer(rd.readLine());
        Integer n=Integer.parseInt(line.nextToken());

        if (n>0)
            wr.println((n*(n+1))/2);

            else
            {
                n=Math.abs(n);
                wr.println(1-(n*(n+1)/2));
            }
        wr.close();
        System.exit(0);



    }

}