Timus : 1023 (Buttons)



// http://acm.timus.ru/problem.aspx?space=1&num=1023
// Tag: Game, Gotcha

#include <stdio.h>
#include <math.h>

int minL (int n)
{
    if ( n == 4 ) return 3;

    int len = sqrt (n * 1.0);

    for ( int i = 3; i <= len; i++ ) 
        if ( n % i == 0 ) return i - 1;

    return n % 2 == 0 ? n / 2 - 1 : n - 1;
}

int main ()
{
    int n; scanf ("%d", &n);

    printf ("%d\n", minL (n));

    return 0;
}

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