Help me in solving OG problem

My issue

Can anyone help??
Don’t see the code, I first implemented it using the for loop in which, I iterated over every integer but it was wrong
so i found another approach in which I calculated the sum of 1-9 and then multiply it with the number i.e. modulus of the given number and then adding the remaining.

Actually I can’t express it in words nor I was successful in writing it as code,
If you have a code for this question, then please provide it.

My code

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

// int sumOfDigits(long long int n) {
//     int sum = 0;
//     while (n > 0) {
//         sum += n % 10;
//         n /= 10;
//     }
//     return sum;
// }

// int origin(long long int n) {
//     while (n >= 10) {
//         n = sumOfDigits(n);
//     }
//     return n;
// }

// int main() {
//     int t;
//     cin >> t;
//     while (t--) {
//         long long int n;
//         cin >> n;
//         long long int total = 0;
//         for (long long int i = 1; i <= n; i++) {
//             total += origin(i);
//         }
//         cout << total << endl;
//     }
//     return 0;
// }

int origin(int n){
    int count = 0;
    for (int i=1; i<=n; i++){
        count+=i;
    }
    // cout << count << endl;
    return count;
}
// a=9, b=45
int main(){
    int t;
    cin >> t;
    while (t--){
        long long int n;
        cin >> n;
        int a,b;
        long long int total = 0;
        // while (n<=10){
            // a = n - (n%9);
            a=9;
            int first = n%a;
            // b = (n/9) * 45;
            b=45;
            int second = n - first*a;
            total += (first*b);
            // cout << total << endl;
            total += origin(second);
        // }
        cout << total << endl;
    }
}

Problem Link: Origin Practice Coding Problem - CodeChef

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

int main() {
	int t;
	cin>>t;
	while(t--){
	    long long n;
	    cin>>n;
	    long long rem = n%9;
	    long long mul = n/9;
	    long long sum = 0;
	    for(int i=1;i<=rem;i++){
	        sum+=i;
	    }
	    sum += mul*45;
	    cout<<sum<<endl;
	}

}