• + 0 comments

    C++

    int viralAdvertising(int n) {
        stack<int> st;
        st.push(0);
        int tmp = 5;
        int t = 0;
        for (int i = 1; i <= n; i++) {
            t = floor(tmp / 2) + st.top();
            tmp = floor(tmp / 2) * 3;
            st.push(t);
        }
    
        return t;
    }