UVa 10346

From Algorithmist
Jump to: navigation, search

10346 - Peter's Smokes[edit]

Summary[edit]

Peter has n cigarettes. He smokes them one by one keeping all the butts. Out of k > 1 butts he can roll a new cigarette.

How many cigarettes can Peter have?

Explanation[edit]

After each round of smokes, determine the number of cigarette butts. Perform integer division on the number of butts each round to determine the number of new cigarettes.

Gotchas[edit]

Don't lose track of any unused cigarette butts.

Notes[edit]

Implementations[edit]

#include<stdio.h>
int main() {
  long int n,i;
  while(scanf("%ld%ld",&n,&i)==2) {
    printf("%ld\n",n+(n-1)/(i-1));
  }
  return 0;
}

Optimizations[edit]

Input[edit]

4 3
10 3
100 5

Output[edit]

5
14
124

References[edit]