title: Is ther any other way to get sum 1 to 100 with recursion?
body: <p>I'm studing recursive function and i faced question of</p>
  <p>&quot;Print sum of 1 to n with no 'for' or 'while' &quot;</p>
  <p>ex ) n = 10</p>
  <p>answer =
  55</p>
  <p>n = 100</p>
  <p>answer = 5050</p>
  <p>so i coded</p>
  <pre><code>import sys
  sys.setrecursionlimit(1000000)
  
  sum = 0
  def count(n):
      global sum
      sum += n
      if n!=0:
          count(n-1)
  count(n = int(input()))
  print(sum)
  </code></pre>
  <p>I know it's not good way to get right answer, but there was a solution</p>
  <pre><code>n=int(input())
  
  def f(x) :
      if x==1 :
          return 1
      else :
          return ((x+1)//2)*((x+1)//2)+f(x//2)*2
  
  print(f(n))
  </code></pre>
  <p>and it works super well , but i really don't know how can human think that logic and i have no idea how it works.</p>
  <p>Can you guys explain how does it works?
  Even if i'm looking that formula but i don't know why he(or she) used like that
  And i wonder there is another solution too (I think it's reall important to me)</p>
  <p>I'm really noob of python and code so i need you guys help, thank you for watching this</p>