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

Common Board

1131
Posted by Farhad Ghasemi 25 Jan 2008 16:21
I get timelimit error what should I do ?
any better algo ?!

#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;

int main()
{
    int n,k;
    char line[100];
    scanf("%s",line);
    n=atoi(line);
    scanf("%s",line);
    k=atoi(line);
    int power=1;
    int h=1;
    int sum=2;
    if(k>=(n/2))
    {
        while(pow(2,h)<n)
            h++;
    }
    else
    {
        while(sum<=k)
        {
            sum*=2;
            h++;
        }
        while(sum<=n)
        {
            sum+=k;
            h++;
        }

    }
    cout<<h;
    return 0;




}