Submission

Status:
PPPPPPPPPP

Score: 100

User: Nathlol2

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

Language: cpp

Time: 0.002 second

Submitted On: 2025-03-16 19:15:50

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

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    if(n == 1){
        cout << "1\n";
        return 0;
    }else if(n == 2){
        cout << "7\n";
        return 0;
    }else if(n == 3){
        cout << "24\n";
        return 0;
    }
    if(n % 2 == 0){
        int ans = 0;
        int p = 6;
        int lp = 14;
        for(int i = 0;i<n / 2 - 1;i++){
            ans += ((n * n) - p) % 10;
            ans += ((n * n) - p + 1) % 10;
            p = p + lp;
            lp += 8;
        }
        ans += (n * n) % 10;
        ans += ((n * n) - 1) % 10;
        cout << ans << '\n';
    }else{
        int ans = 0;
        int p = 2;
        int lp = 10;
        for(int i = 0;i<n / 2;i++){
            ans += ((n * n) - p) % 10;
            ans += ((n * n) - p + 1) % 10;
            p = p + lp;
            lp += 8;
        }
        ans += (n * n) % 10;
        cout << ans << '\n';
    }
}