ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1353. Milliard Vasya's Function

С++ code for brute force
Posted by D4nick 11 Mar 2020 14:39
#include <stdio.h>
#include <map>
using namespace std;
int main() {
    int ans, sum, ost, s; long int full, i; map <long int, int> sums;
    for (i = 1; i <= 1000000000; i++) {
        sum = 0; full = i;
         do {
            ost = full % 10;
            full /= 10;
            sum += ost;
         } while (full > 0);
         sums[i] = sum;
    }
    for (s = 1; s <= 81; s++) {
        ans = 0;
        for (i = 1; i <= 1000000000; i++)
            if (sums[i] == s)
                ans++;
        printf("{%ld}, ", ans);
    }
}

it will give you {10}, {...}, ... , {...}, vector that you can use for getting AC with O(1).

Edited by author 11.03.2020 14:40

Edited by author 11.03.2020 14:44