11592 - Change the Cap
raw download clone
C
views 21
,
size 602 b
#include <stdio.h>

int main(void)
{
    int n, ans, q, r, temp;
    int l[10001] = {0};

    for(int i=1; i<=10000; i++)
    {
        ans = 0;
        q = i / 3;
        r = i % 3;
        ans += q;
        while((q + r) >= 3)
        {
            ans += (q + r) / 3;
            temp = q;
            q = (q + r) / 3;
            r = (temp + r) % 3;
        }
        l[i] = ans + i;
    }
    scanf("%d", &n);
    for(int j=1; j<=10000; j++)
    {
        if(l[j] >= n)
        {
            printf("%d\n", j);
            break;
        }
    }

    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.