67 in 2026?#12418

67 in 2026? (Editorial)

Problem Author:

De3b0o

Prepared by:

De3b0o

Edited by:

Hasan Saleh (MathModel)

Solution

Let's look at these two cases:

x \le 0

In this case it's never optimal to multiply because it would make smaller, so we always add .

x > 0

It's easy to see that in this case it's always optimal to multiply by instead of adding .

So we can just simulate the process.

Complexity \mathcal{O}(t \cdot k).


#include <bits/stdc++.h>
#define ll long long

using namespace std;

void solve()
{
    ll x , k;
    cin >> x >> k;
    while(k--)
    {
        if(x>0)
            x*=7;
        else
            x+=6;
    }
    cout << x << "\n";
}

int main()
{
    ll T=1;
    cin >> T;
    while(T--)
        solve();
}