Блог пользователя rpthegreat

Автор rpthegreat, 9 лет назад, По-английски

I am trying to solve a problem which is described below,

Given value of f(0) and k , which are integers.

I need to find value of f( T ). where T<=10^10 (10 power 10)

Recursive function is,

f(n) = 2*f(n-1) , if 4*f(n-1) <=k

k - ( 2*f(n-1) )      ,  if 4*f(n-1) > k

If i solve by brute force then it will give me TLE. The code will run 10^10(10 power 10) time in worst case that gives me Time Limit Exceed. I need more efficient solution for this problem. Please help me. I don't know the correct algorithm.

  • Проголосовать: нравится
  • +5
  • Проголосовать: не нравится

»
9 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by rpthegreat (previous revision, new revision, compare).

»
9 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by rpthegreat (previous revision, new revision, compare).

»
9 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

What are the constrainsts of k and f0?

»
9 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Why don't you give link to the problem?

»
9 лет назад, скрыть # |
 
Проголосовать: нравится -10 Проголосовать: не нравится

u can print a value table in ur own computer,about every 100000 print one f(i),then u only need to calculate 100000 times in worst case.(u can adjust the interval 2 satisfy the limit of problem)