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 1131. Copying

time exceeded。。can you help me make it faster?
Posted by xinxin 16 Sep 2016 19:06
#include<stdio.h>
#include<math.h>

int main()
{
    int n,k,i=1,s=1,t=0,temp=0;
    scanf("%d %d",&n,&k);

    while(i<k)
    {
        s=s+i;
        i=2*i;
        t++;

        if(s>=n)
            break;
    }
    while(s<n)
    {
        s=s+k;
        t++;
    }

    printf("%d",t);
    return 0;
}
Re: time exceeded。。can you help me make it faster?
Posted by ToadMonster 23 Sep 2016 16:30
    while(s<n)
    {
        s=s+k;
        t++;
    }

Isn't here (n-s)/k iterations?
Re: time exceeded。。can you help me make it faster?
Posted by Said 15 May 2020 04:21
#pragma optimize( "g", on )