/ 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 340.0 KiB
#5 Accepted 1ms 532.0 KiB
#6 Accepted 1ms 344.0 KiB
#7 Accepted 1ms 532.0 KiB
#8 Accepted 1ms 488.0 KiB
#9 Accepted 1ms 516.0 KiB
#10 Accepted 1ms 564.0 KiB

Code

#include <bits/stdc++.h>     //   All praise is due to Allah alone, and peace and blessings be
using namespace std;         //         upon him, after whom there is no other Prophet.


int32_t main() {
    cin.tie(0)->sync_with_stdio(false);

    int32_t Case = 1;    //cin >> Case;
    for (int T = 1; T <= Case; T++) {

        string s; cin >> s;
        int64_t n; cin >> n;

        string a, b;
        int i = 0;
        for( i = 0; i < s.size(); i++) {
            if(s[i] == '+') break;
            a.push_back(s[i]);
        }
        for(i++; i < s.size(); i++) {
            if(s[i] == '+') break;
            b.push_back(s[i]);
        }
        int64_t A = stoll(a), B = stoll(b);
        __int128_t ans = (A * 2 + (n - 1) * (B - A));
        ans *= n; 
        ans /= 2;
        string ok;
        while(ans) {
            ok.push_back(char(ans % 10 + '0')); ans /= 10;
        }
        reverse(ok.begin(), ok.end());
        if(ok.empty()) cout << "0\n";
        else cout << ok << '\n';
    }
    return 0;
}

// 2.5 * (2 + 4 * 2)

Information

Submit By
Type
Submission
Problem
P1231 Busy Friend
Contest
LUCC Presents Intra LU Junior Programming Contest - Replay
Language
C++17 (G++ 13.2.0)
Submit At
2025-09-02 16:46:21
Judged At
2025-09-02 16:46:21
Judged By
Score
100
Total Time
1ms
Peak Memory
564.0 KiB