Sort by

recency

|

55 Discussions

|

  • + 0 comments

    hard question, finally got it working after numerous modifications to improve time. hint: dont use pow(2, K), it's slow as fk, precompute the powers of 2 and 10

    calculating global information requires O(300000 * 19 * 10). let A be the x'th decibinary number. each query for x <= 10^16 takes O(log_2(300000) + log_10(A))

    pass all tests no timeout

    vector<vector<long>> cache(300000, vector<long>(19)), two(10, vector<long>(19)), ten(10, vector<long>(19));
    vector<long> decimalValue;
    
    void global_information() {
        for (int K = 0; K <= 18; ++K) {
            for (int d = 0; d <= 9; ++d) {
                two[d][K] = d * pow(2, K);
                ten[d][K] = d * pow(10, K);
            }
        }
        for (int K = 0; K <= 18; ++K) cache[0][K] = 1;
        for (int n = 0; n <= 9; ++n) cache[n][0] = 1;
        for (int n = 1; n < cache.size(); ++n) {
            for (int K = 1; K <= 18; ++K) {
                for (int d = 0; d <= 9 and n - two[d][K] >= 0; ++d) cache[n][K] = cache[n][K] + cache[n - two[d][K]][K - 1];
            }
        }
        decimalValue.push_back(1);
        for (int n = 1; n < cache.size(); ++n) decimalValue.push_back(decimalValue.back() + cache[n][18]);
    }
    
    long decibinaryNumbers(long x) {
        if (x == 1) return 0;
        long answer = 0;
        int v = distance(decimalValue.begin(), lower_bound(decimalValue.begin(), decimalValue.end(), x));
        long position = x - decimalValue[v - 1];
        while (v > 0) {
            int K = distance(cache[v].begin(), lower_bound(cache[v].begin(), cache[v].end(), position)), d = 0;
            if (K == 0) {
                answer = answer + v;
                break;
            }
            long temp = 0;
            for (int digit = 0; digit <= 9 and v - two[digit][K] >= 0; ++digit) {
                temp = temp + cache[v - two[digit][K]][K - 1];
                if (position <= temp) {
                    d = digit;
                    break;
                }
            }
            answer = answer + ten[d][K];
            position = position - temp + cache[v - two[d][K]][K - 1];
            v = v - two[d][K];
        }
        return answer;
    }
    
    int main()
    {
        global_information();
        int q;
        long x;
        cin >> q;
        for (int i = 1; i <= q; ++i) {
            cin >> x;
            cout << decibinaryNumbers(x) << '\n';
        }
    }
    
  • + 0 comments

    Decibinary numbers present an intriguing mathematical concept where each digit's value is restricted to a decimal system, but the overall number follows binary rules. These numbers require a unique approach to understand and manipulate, blending elements of both decimal and binary systems. In practical applications, they offer interesting challenges and opportunities for problem-solving in computer science and digital logic design. As enthusiasts delve into the complexities of decibinary numbers, they often find themselves needing tangible aids, like trolley coins, to visualize and calculate these unique values. Trolley coins, used for practical problem-solving, symbolize the intersection of theoretical mathematics and real-world utility.

  • + 0 comments

    In the decibinary system, each digit position represents a power of 2, just like in binary. However, unlike binary, where each digit represents 2 𝑖 2 i (where 𝑖 i is the position of the digit from right to left), in decibinary numbers, each digit represents 2 𝑖 2 i multiplied by a chosen base, typically 10. This allows for the representation of larger numbers using fewer digits compared to binary.

  • + 0 comments

    "Decibinary Numbers" is a mathematical concept that represents numbers in a unique base system, where each digit position has a weight corresponding to powers of ten. This system is particularly useful for efficiently representing large numbers with a limited set of digits. While exploring the complexities of "Decibinary Numbers," don't miss out on the exclusive offers available at Nesto offers. Discover unbeatable deals and savings on a wide range of products, enhancing your shopping experience with every purchase.

  • + 3 comments

    in swift

    I am getting failed in test case 6,7,8. Any help and suggestion would be appreciated

    import Foundation
    
    var arr: [[Int]] = [[0], [1]]
    
    func calculateNumber(number: Int) -> Int {
        if arr.count > number {
                return arr[number].count
        }
    
        var array = [Int]()
    
        let from = number > 9 ? 9 : number
        for i in stride(from: from, through: 0, by: -1) where (number - i) % 2 == 0 {
                let extraNumber = (number - i) / 2
                if arr.count > extraNumber {
                        for a in arr[extraNumber] {
                                array.append(a * 10 + i)
                        }
                }
        }
    
        array.sort()
        array.reversed()
        arr.append(array)
        return array.count
    }
    
    func decibinaryNumbers(x: Int) -> Int {
        var prevLength = 0
        var length = 0
        var i = 0
        while true {
                length += calculateNumber(number: i)
                if length >= x {
                        break
                }
                i += 1
                prevLength = length
        }
    
        let index = x - prevLength - 1
        return arr[i][index]
    }
    
    let q = Int(readLine()!)!
    
    for _ in 1...q {
        let x = Int(readLine()!)!
        print(decibinaryNumbers(x: x))
    }