Submission #59945745
Source Code Expand
import java.io.*;
import java.util.*;
import java.util.function.Function;
public class Main
{
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble() { return Double.parseDouble(next()); }
int[] nextIntArray(int n)
{
int[] ans = new int[n];
for(int i = 0; i < n; i++)
ans[i] = nextInt();
return ans;
}
Integer[] nextIntegerArray(int n)
{
Integer[] ans = new Integer[n];
for(int i = 0; i < n; i++)
ans[i] = nextInt();
return ans;
}
long[] nextLongArray(int n)
{
long[] ans = new long[n];
for(int i = 0; i < n; i++)
ans[i] = nextLong();
return ans;
}
String[] nextStringArray(int n)
{
String[] ans = new String[n];
for(int i = 0; i < n; i++)
ans[i] = next();
return ans;
}
String nextLine()
{
String str = "";
try {
if(st.hasMoreTokens()){
str = st.nextToken("\n");
}
else{
str = br.readLine();
}
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static final int mod = (int)(1e9) + 7;
static final long INF = (long)(1e18);
static final int INF_INT = (int)(1e9);
private static int gcd(int a, int b)
{
if(a % b == 0)
return b;
return gcd(b, a % b);
}
static class TreeNode
{
int start, end;
TreeNode left, right;
int len;
TreeNode(int a, int b)
{
set(a, b);
left = right = null;
}
void set(int a, int b)
{
start = a;
end = b;
len = end - start + 1;
}
}
static class Pair
{
int dest;
long distance;
Pair(int a, long b)
{
dest = a;
distance = b;
}
public String toString()
{
return "(" + dest + ", " + distance + ")";
}
}
static class Slope
{
int n, d;
Slope(int a, int b)
{
n = a;
d = b;
if(d == 0)
n = 1;
else if(n == 0)
d = 1;
else
{
int hcf = gcd(n, d);
n /= hcf;
d /= hcf;
}
}
public double slope()
{
return (double)n / d;
}
public boolean equals(Slope ob)
{
return n == ob.n && d == ob.d;
}
public String toString()
{
return String.format("(%d, %d)", n, d);
}
}
static class DSU
{
int n;
int[] parent;
int[] size;
public DSU(int _n)
{
n = _n;
parent = new int[n];
size = new int[n];
for(int i = 0; i < n; i++)
{
parent[i] = i;
size[i] = 1;
}
}
public int findParent(int node)
{
if(node == parent[node])
return node;
return parent[node] = findParent(parent[node]);
}
public void union(int u, int v)
{
int rootU = findParent(u), rootV = findParent(v);
if(rootU != rootV)
{
if(rootU < rootV)
{
parent[rootV] = rootU;
size[rootU] += size[rootV];
size[rootV] = 0;
}
else
{
parent[rootU] = rootV;
size[rootV] += size[rootU];
size[rootU] = 0;
}
}
}
public boolean same(int u, int v)
{
return findParent(u) == findParent(v);
}
}
static Long[][] dp;
static int[][] trace;
static Function<Integer, Integer> f1;
public static void main(String args[]) throws IOException
{
FastReader fr = new FastReader();
// Scanner fr = new Scanner(System.in);
// Scanner fr = new Scanner(new File("C:\\Users\\ykgup\\Downloads\\test_input.txt"));
// int _t = fr.nextInt();
int _t = 1;
// int _case = 1;
StringBuilder _v = new StringBuilder();
PrintWriter out = new PrintWriter(System.out);
while(_t-- > 0)
{
int n = fr.nextInt();
// n = 5
// positions = [1, 2, 3, 4, 5]
// candies = [1, 2, 3, 4, 5]
// ans = 1 + 2 + 3 + 4 + 5
// a_i = x
// a_{i+1} = x+1
// AP: a_0 = 1, d = 1
// S_n = (n / 2) * (2 * a_0 + (n - 1) * d)
// S_5 = (5 / 2) * (2 * 1 + (5 - 1) * 1)
// S_5 = 2.5 * (2 + 4) = 2.5 * 6 = 15
// S_5 = 1 + 2 + 3 + 4 + 5 = 15
// S_n = (n / 2) * (2 * 1 + (n - 1) * 1) = (n / 2) * (2 + n - 1) = (n / 2) * (n+1)
// S_n = n * (n+1) / 2
_v.append(n * (n+1) / 2);
_v.append("\n");
// _v.append("Case");
// _v.append(" ");
// _v.append(_case++);
// _v.append(": ");
}
out.print(_v);
out.flush();
}
}
Submission Info
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
100 / 100 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
0_000.txt, 0_001.txt, 0_002.txt |
| All |
0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 0_000.txt |
AC |
39 ms |
34432 KiB |
| 0_001.txt |
AC |
38 ms |
34504 KiB |
| 0_002.txt |
AC |
37 ms |
34312 KiB |
| 1_003.txt |
AC |
38 ms |
34568 KiB |
| 1_004.txt |
AC |
37 ms |
34296 KiB |
| 1_005.txt |
AC |
40 ms |
34084 KiB |