Polish version    English version  
  About Olympic -> Problems


 News
 About Olympic
About contest
Problems
I OI 1993/1994
II OI 1994/1995
III OI 1995/1996
IV OI 1996/1997
V OI 1997/1998
VI OI 1998/1999
VII OI 1999/2000
VIII OI 2000/2001
IX OI 2001/2002
X OI 2002/2003
XI OI 2003/2004
XII OI 2004/2005
XIII OI 2005/2006
XIV OI 2006/2007
XV OI 2007/2008
Problems archive
 History of OI
 OI books
 National team
 Olympic camps
 Photo gallery
 Links
 SIO
 MAIN
Niebieskie ksi.eczki
III Olympiad in Informatics 1995/1996

Task: FIB
Author: Wojciech Rytter
Fibonacci words

II stage contest  

Fibonacci words are defined similarly to Fibonacci numbers:  
    FIB1 = b     FIB2 = a     FIBk+2 = FIBk+1*FIBk for k >= 1,
where * denotes operation of connecting words (concatenation). 

Hence we have:
FIB3 = ab;     FIB4 = aba;     FIB5 = abaab;     FIB6 = abaababa.

 

Task

Write a program that:
  • reads from the text file FIB.IN a word comprising at least one and at most 30 characters a or b, and one positive integer n <= 200,
  • computes how many times the word appears in the n-th Fibonacci word FIBn (how many fragments of FIBn are the same as the given word; the fragments may partially overlap).
  • writes the result in the text file FIB.OUT.

Input

In the first line of the text file FIB.IN there is written one word. The word is composed of at least one and at most 30 characters a or b. In the second line there is written one positive integer n <= 200.

Output

In the text file FIB.OUT there should be written one nonnegative integer. It should be equal to the number of times the given word appears in the Fibonacci word FIBn.  

Example

For the input file FIB.IN:
aba
6

In the output file FIB.OUT should be written one integer:
3

Your program should look for the file FIB.IN in the current directory and produce the output file FIB.OUT in the current directory too. The file containing the source code of your program should have a name FIB.???, whereas you should put three-letter abbreviation of the used programming language name instead of ???. The same program in executable form should be written in the file FIB.EXE




Print friendly version