|
|
back to boardDiscussion of Problem 1068. SumSolution 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);
} } |
|
|