Initially, each screen shows the number zero. Pressing the first button increments the number on the first screen by 1, and each click of the first button consumes 1 unit of energy.

Pressing the second button increases the number on the second screen by the number which is currently appearing on the first screen. Each click of the second button consumes B units of energy.

Initially the calculator has N units of energy.

1 ≤ N, B ≤ 1,000,000,000

inputs are N and B having large values ~10^9

```
long long N,B;
cin >> N >> B;
long long val1=0;
long long val2=0;
for(int64_t i=0;i<N;i++)
{
val1++;
val2=0;
long long left = N-i-1;
if(left%B==0)
{
val2 = (left/B)*val1;
cout << val2 << endl;
}
maxval = max(maxval,val2);
if(val2<maxval && val2!=0)
{
break;
}
} ```
my codeis getting time limit exceed cause time limit is 1 sec..
how and where to optimize
```