uva online judge self describing sequence problem solution python | uva 10049

The self describing sequence problem  (uva 10049) is also very straight forward and easy programming challenge in competitive programming once understood well. Which can be stated as (from online judge) Solomon Golomb’s self–describing sequence ⟨f(1),f(2),f(3),...⟩ is the only nondecreasing sequence of positive integers with the property that it contains exactly f(k) occurrences of k for each k. A few moments thought reveals that the sequence must begin as follows: n 1 2 3 4 5 6 7 8 9 10 11   12 f(n) 1 2 2 3 3 4 4 4 5 5 5 6 In this problem you are expected to write a program that calculates the value of f(n) given the value of n. Sample Input 100  9999  123456  1000000000  0 Sample Output 21  356  1684  438744 Programming Explanation This is very simple problem states that for given range of n as input (as shown in above image), we have

uva online judge how many fibs problem solution python | uva 10183

How many fibs? problem (uva 10183) is one of the easiest programming challenge in competitive programming. Which can be stated as (from online judge)

Recall the definition of the Fibonacci numbers:
f1 := 1 
f2 := 2 
fn := fn−1 + fn−2    (n ≥ 3) 

Given two numbers a and b, calculate how many Fibonacci numbers are in the range [a,b].

That's it, our jobs is to calculate total number of fibonacci numbers in given range. This problem is pretty straight forward and doesn't need any explanation.

Sample Input

10 100 
1234567890 9876543210 
0 0

Sample Output

4

Code

fibbo = []
a = 1
b = 1
fibbo.append(a)
fibbo.append(b)


for i in range(0, 100):
    temp = a + b
    fibbo.append(temp)
    a = b
    b = temp

z = input().split(" ")
a = int(z[0])
b = int(z[1])

count = 0
if (a <= 1):
    count = 2

for temp in fibbo:
    if(temp >= a and temp <= b):
        count+=1

print(count)

Here, assuming that user range will consist first 100 fibonacci numbers thus we first calculate fibonacci series upto 100 as series length, and store it in 'fibbo' list. Then we simple check how many numbers belongs to given range and display count.

Hope, this article found helpful for you. Thank you.


Related keywords: how many fibs, how many fibs problem, how many fibs uva, how many fibs online judge, how many fibs solution, how many fibs explanation, how many fibs programming challenge, how many fibs solution python, uva 10183, uva 10183 problem solution python,uva 10183 source code python.

Comments

  1. This comment has been removed by a blog administrator.

    ReplyDelete

Post a Comment

Popular posts from this blog

uva online judge vito's family problem solution python | uva 10041

uva online judge australian voting problem solution python | uva 10142

uva online judge common permutation problem solution python | uva 10252