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 limit on python 3 HELP PLEASE I GIVE MONEY
Posted by ivan228 17 Oct 2018 22:34
import sys
n,k=map(int,input().split())
ans=0
nn=1
on=1
if n==1:
    print(0)
    sys.exit()
for i in range(100000000000000000000):
    if on<=k:
        nn+=on
        on+=on
        ans+=1
    elif k<n:
        nn+=k
        on+=k
        ans+=1
    if nn>=n:
        print(ans)
        sys.exit()
i can not understand why optimization my cod
if i got ac with you help i give you 1000 rubles

Edited by author 17.10.2018 22:35
Re: time limit on python 3 HELP PLEASE I GIVE MONEY
Posted by a.menshchikov 25 Nov 2018 08:59
n, k = map(int, input().split())

gamed = 1
res = n - 1
t = 0

while res > 0:
    if gamed >= k and k <= res:
        gk = res // k
        res %= k
        gamed += gk*k
        t += gk
        continue
    g = min(gamed, k, res)
    gamed += g
    res -= g
    t += 1
print(t)
Re: time limit on python 3 HELP PLEASE I GIVE MONEY
Posted by Skeef79 25 Dec 2018 16:04
Чувак, твоя принять просто не успевает по времени , у тебя цикл дофига итераций, а Пайтон уже при цикле в 1000000 больше секунды работает. Так что важно успеть за отведенное время.

Вообще можно делать так:
#include<iostream>
#include<cmath>
using namespace std;

int main()
{
    long long n,k;
    cin>>n>>k;
    //ceil

    long long s = int(log2(k))+1;

    if ( n-pow(2,s)>0)
    s = s + ceil((n-pow(2,s))/k);
    else
    s = int(ceil((log2(n))));
    cout<<s;

}