UVa : 11384 (Help is needed for Dexter)



// http://uva.onlinejudge.org/external/113/11384.html
// Runtime: 0.048s
// Tag: Binary, power of 2

#include <stdio.h>

int main ()
{
    int n;
    int a [32];
    a [0] = 1;

    for ( int i = 1; i < 32; i++ ) a [i] = a [i - 1] * 2;

    while ( scanf ("%d", &n) != EOF ) {
        for ( int i = 0; i < 32; i++ ) {
            if ( n < a [i] ) { printf ("%d\n", i); break; }
        }
    }

    return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s