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 1044. Lucky Tickets. Easy!

Brute force Accept in 1.625
Posted by zser 8 Jun 2025 20:41
#include <bits/stdc++.h>
using namespace std;

int cal(int x){
    int ret = 0;
    while (x > 0){
        ret += x % 10;
        x /= 10;
    }
    return ret;
}

bool lucky(int x, int mm){
    int a = x / mm;
    int b = x % mm;
    if (cal(a) == cal(b)) return true;
    return false;
}

int main(){
    int n;
    cin >> n;
    int nn = round(pow(10, n)) - 1;
    int mm = round(pow(10, n / 2));
    int tot = 0;
    for (int i = 0; i <= nn; i++){
        if (lucky(i, mm)) tot++;
    }
    cout << tot << endl;
}

if your code is simple and fast enough, brute force can work.