ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1023. Buttons

AC program
Posted by MSDN 21 Dec 2007 12:24
It's very easy problem!
These examples are drawing solution:
K=8
f - first player
s - second player
*******
L=2
1 2 3 4 5 6 7 8
f f s f f s f f
*******
L=3
1 2 3 4 5 6 7 8
f f f s f f f s
*******
In these examples you can see  minimum L = (minimal divider of K) - 1
Code:
#include <stdio.h>
#include <math.h>
typedef unsigned long int INT;

void main()
{
    INT A,i,sq;
    scanf("%lu",&A);
    sq=(INT)powl(A,0.5);
    for(i=3;i<=sq;i++)
        if(A%i==0)
        {
            printf("%lu",i-1);
            return;
        }
    if((A%2!=0)||(A/2==2)) printf("%lu",A-1);
    else printf("%lu",A/2-1);
}

Edited by author 21.12.2007 12:25

Edited by author 21.12.2007 12:26

Edited by author 21.12.2007 12:26

Edited by author 21.12.2007 12:26