/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 536.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Accepted 1ms 532.0 KiB
#5 Accepted 1ms 532.0 KiB
#6 Accepted 2ms 536.0 KiB
#7 Accepted 4ms 504.0 KiB
#8 Accepted 4ms 424.0 KiB
#9 Accepted 4ms 532.0 KiB
#10 Accepted 4ms 532.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"

int get_int(string s) {
    int ans = 0;
    int k = 1;

    for (int i = s.size()-1; i >= 0; i--) {
        int x = s[i] -'0';
        ans += x * k;
        k *= 10;
    }
    return ans;
}

int main() {
    string s; cin >> s;
    ll n; cin >> n;
    string a = "";
    string b = "";
    int i;
    int j;
    for (i = 0; i < s.size(); i++) {
        if(s[i] == '+'){
            j = i + 1;
                break;
        }
       else  a += s[i];
    }


    for ( int i = j; i < s.size(); i++) {
        if(s[i] == '+')break;
        b += s[i];
    }
       // cout << a << " " << b << endl;
   // cout << a << " " << b << " " << n << endl;

    ll d = get_int(b) - get_int(a);

    ll ans = (n *( 2 * get_int(a) + (n - 1) * d)) / 2;

    cout << ans << endl;

}

Information

Submit By
Type
Submission
Problem
P1231 Busy Friend
Contest
LUCC Presents Kick & Code Intra LU Programming Contest
Language
C++17 (G++ 13.2.0)
Submit At
2025-09-01 06:57:27
Judged At
2025-09-01 06:57:27
Judged By
Score
100
Total Time
4ms
Peak Memory
536.0 KiB