Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <unordered_map>
- #include <vector>
- std::string intToBase(int x, int base)
- {
- if (x < base) {
- return std::to_string(x);
- }
- return intToBase(x/base, base) + std::to_string(x % base);
- }
- int main()
- {
- int n;
- std::cin >> n; std::cin.get();
- for (int i=0; i<n; i++)
- {
- int b, l, r;
- std::cin >> b >> l >> r; std::cin.get();
- int goodCount = 0;
- for (int num = l; num <= r; num++)
- {
- bool numIsGood = true;
- std::unordered_map<char, int> counts;
- for (const char digit : intToBase(num, b))
- {
- if (counts.find(digit) == counts.end()) {
- counts[digit] = 0;
- }
- counts[digit]++;
- }
- for (const auto& key_val : counts)
- {
- if ((key_val.second % 2) != 0) {
- numIsGood = false;
- break;
- }
- }
- if (numIsGood) { goodCount++; }
- }
- std::cout << goodCount << std::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement