Competitive Programming Solutions

GitHub
back to dashboard

D. Range Sum

Codeforces - Contest #2 · limit: 1s · memory: 256MB · view on codeforces

input

25
8 999999990
4 999999991
8 1000000000
8 999999996
8 999999998
2 999999998
4 999999991
9 999999994
6 999999998
4 999999994
10 999999997
10 999999992
10 999999998
6 999999999
1 999999992
6 999999998
1 999999994
9 999999998
5 1000000000
3 999999997
2 999999995
10 999999996
5 999999995
6 999999991
10 999999995

output

499999990500000017
499999991500000030
500000000499999972
499999996499999978
499999998499999973
499999998500000000
499999991500000030
499999994499999979
499999998499999986
499999994500000009
499999997499999958
499999992499999983
499999998499999956
499999999499999985
499999992500000028
499999998499999986
499999994500000015
499999998499999965
500000000499999990
499999997500000000
499999995500000009
499999996499999961
499999995500000000
499999991500000021
499999995499999965
Main.java
static void solve() {

        // Write your solution here
        int l = in.nextInt();
        int r = in.nextInt();
        if (l > r) {
        int temp = l;
        l = r;
        r = temp;
        }

        long count = (long) r - l + 1;
        long sum = (long) l + r;
        long result = count * sum / 2;

        out.println(result);
    }