Submission

Status:
P-P-P-P-P-

Score: 50

User: Pera

Problemset: โชว์ของโลมา

Language: cpp

Time: 0.002 second

Submitted On: 2025-03-24 19:11:58

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    long long n; cin >> n;
    if (n == 1) {
        cout << 1 << '\n';
        return 0;
    } else if (n == 2) {
        cout << 2 << '\n';
        return 0;
    }

    long long sum{0};
    long long num{0};
    long long next = n;

    while (next >= 2) {
        num += 2 * next - 2 + next;

        if (num == num * num) {
            sum += (num % 10) + ((num - 1) & 10);
        } else {
            sum += (num % 10) + ((num+1) % 10);
        }

        num += next - 2;
        next -= 2;
    }

    if (n % 2 != 0) sum += (n * n) % 10;
    cout << sum << '\n';
}