|
|
back to boardBrute 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. |
|
|