Saturday, July 19, 2014

Codeforces Round #112 (Div. 2), problem: (B) Burning Midnight Oil solution

Codeforces Round #112 (Div. 2), problem: (B) Burning Midnight Oil: http://codeforces.com/problemset/problem/165/B

Codeforces Round #112 (Div. 2), problem: (B) Burning Midnight Oil editorial: http://codeforces.com/blog/entry/4124

Codeforces Round #112 (Div. 2), problem: (B) Burning Midnight Oil solution: http://ideone.com/lFwbi9


#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    int n, k, tmp, n2, i;
    scanf("%d%d", &n, &k);
    tmp=n-n/k;
    n2=n;
    while(n2>0) {
        n2=n, i=tmp;
        while(i>0) n2-=i, i/=k;
        if(n2>0) tmp++;
    }
    printf("%d", tmp);
    return 0;
}


No comments:

Post a Comment