Editorial for Số may mắn


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.

\(\color{red}{\text{Spoiler Alert}_{{}_{{}^{{}^{v2.0}}}}}\)

\(\color{red}{\text{Khuyến khích bạn đọc trước khi đọc phần lời giải xin hãy thử code ra thuật của mình dù nó có sai hay đúng}}\)

\(\color{red}{\text{Sau đó từ phần bài giải và thuật toán trước đó mà đối chiếu, rút nhận xét với thuật của mình và thu được bài học (không lãng phí thời gian đâu).}}\)



\(\color{orange}{\text{Hint 1}}\)

  • Gọi một bài toán con \(f(n)\) là Số số có \(n\) chữ số mà chỉ gồm số \(6\)\(9\)

Mỗi vị trí chữ số có 2 cách chọn (\(6\) hoặc \(9\)) => có \(2^n\) cách chọn


\(\color{goldenrod}{\text{Hint 2}}\)

  • Gọi kết quả \(res\) là Số số có không quá \(n\) chữ số mà chỉ gồm số \(6\)\(9\)

\(res = f(0) + f(1) + ... + f(n) = 2^0 + 2^1 + .. + 2^n = 2^{n + 1} - 2\)


\(\color{green}{\text{Preference AC Code }}\): Math, Bitwise

\(^{^{\color{purple}{\text{Complexity : }} O(1)\ \color{purple}{\text{time}}\ ||\ O(1)\ \color{purple}{\text{memory}}}}\)

C++
int main()
{
    cout << (1LL << (readInt() + 1)) - 2;
    return 0;
}


Comments

There are no comments at the moment.