2 条题解
-
0
丑陋的打表+前缀和二分。。。
#include <bits/stdc++.h> using u32 = unsigned; using i64 = long long; using u64 = unsigned long long; using u128 = unsigned __int128; int S(i64 x) { int res = 0; while (x) { res += x % 10; x /= 10; } return res; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int L, R; std::cin >> L >> R; std::map<int, int> mp; for (i64 i = 1; i <= R; i++) { i64 p = i; int res = 0; while (p % 10 > 3) { res++; p /= 10; p++; } i = p * std::pow(10, res); if (S(i) * S(i) == S(i * i)) { mp[i]++; } } int res = 0; std::map<int, int> ans; std::vector<int> p; for (auto [x, y] : mp) { p.push_back(x); ans[x] = y + res; res += y; } auto l = lower_bound(p.begin(), p.end(), L) - p.begin() - 1; auto r = upper_bound(p.begin(), p.end(), R) - p.begin() - 1; std::cout << ans[p[r]] - ans[p[l]] << "\n"; return 0; }
信息
- ID
- 137
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 5
- 标签
- 递交数
- 25
- 已通过
- 12
- 上传者