title: Efficiently calculating mathematical formulas with exponents
body: <p>I'm implementing a program that calculates an equation: F(n) = F(n-1) + 'a' + func1(func2(F(n-1))).</p>
  
  <p>func1 takes every 'a' and makes it 'c' and every 'c' becomes 'a'.</p>
  
  <p>func2 reverses the string (e.x. "xyz" becomes "zyx").</p>
  
  <p>I want to calculate the Kth character of F(10**2017).
  The basic rules are F(0) = "" (empty string), and examples are F(1) = "a", F(2) = "aac", and so on.</p>
  
  <p>How do I do this efficiently?</p>
  
  <p>The basic part of my code is this:</p>
  
  <pre><code>def op1 (str1):
       if str1 == 'a':
            return 'c'
       else:
            return 'a'
  
  def op2 (str2):
       return str2[::-1]
  
  sinitial = ''
  
  while (counter &lt; 10**2017):
      Finitial = Finitial + 'a' + op1(op2(Finitial))
      counter += 1
  
  print Finitial
  </code></pre>