'''simple docstring'''

from __future__ import annotations

from fractions import Fraction
from math import gcd, sqrt


def __a (	__lowerCamelCase			:						int				)	->							bool:
      '''simple docstring'''


      lowercase_     =      int(number**0.5				)
      return number == sq * sq


def __a (	__lowerCamelCase			:						int ,		__lowerCamelCase			:						int ,		__lowerCamelCase			:						int ,		__lowerCamelCase			:						int ,		__lowerCamelCase			:						int ,		__lowerCamelCase			:						int				)	->							tuple[int, int]:
      '''simple docstring'''


      lowercase_     =      x_num * y_den * z_den + y_num * x_den * z_den + z_num * x_den * y_den
      lowercase_     =      x_den * y_den * z_den
      lowercase_     =      gcd(__lowerCamelCase ,		__lowerCamelCase				)
      top //= hcf
      bottom //= hcf
      return top, bottom


def __a (	__lowerCamelCase			:						int = 35				)	->							int:
      '''simple docstring'''


      lowercase_     =      set()
      lowercase_     =      42
      lowercase_     =      Fraction(0				)
      lowercase_     =      42

      for x_num in range(1 ,		order + 1				):
            for x_den in range(x_num + 1 ,		order + 1				):
                  for y_num in range(1 ,		order + 1				):
                        for y_den in range(y_num + 1 ,		order + 1				):
                              # n=1
                              lowercase_     =      x_num * y_den + x_den * y_num
                              lowercase_     =      x_den * y_den
                              lowercase_     =      gcd(__lowerCamelCase ,		__lowerCamelCase				)
                              z_num //= hcf
                              z_den //= hcf
                              if 0 < z_num < z_den <= order:
                                    lowercase_     =      add_three(
                                        __lowerCamelCase ,		__lowerCamelCase ,		__lowerCamelCase ,		__lowerCamelCase ,		__lowerCamelCase ,		__lowerCamelCase				)
                                    unique_s.add(__lowerCamelCase				)

                              # n=2
                              lowercase_     =      (
                                  x_num * x_num * y_den * y_den + x_den * x_den * y_num * y_num
                              )
                              lowercase_     =      x_den * x_den * y_den * y_den
                              if is_sq(__lowerCamelCase				) and is_sq(__lowerCamelCase				):
                                    lowercase_     =      int(sqrt(__lowerCamelCase				)				)
                                    lowercase_     =      int(sqrt(__lowerCamelCase				)				)
                                    lowercase_     =      gcd(__lowerCamelCase ,		__lowerCamelCase				)
                                    z_num //= hcf
                                    z_den //= hcf
                                    if 0 < z_num < z_den <= order:
                                          lowercase_     =      add_three(
                                              __lowerCamelCase ,		__lowerCamelCase ,		__lowerCamelCase ,		__lowerCamelCase ,		__lowerCamelCase ,		__lowerCamelCase				)
                                          unique_s.add(__lowerCamelCase				)

                    # n=-1
                              lowercase_     =      x_num * y_num
                              lowercase_     =      x_den * y_num + x_num * y_den
                              lowercase_     =      gcd(__lowerCamelCase ,		__lowerCamelCase				)
                              z_num //= hcf
                              z_den //= hcf
                              if 0 < z_num < z_den <= order:
                                    lowercase_     =      add_three(
                                        __lowerCamelCase ,		__lowerCamelCase ,		__lowerCamelCase ,		__lowerCamelCase ,		__lowerCamelCase ,		__lowerCamelCase				)
                                    unique_s.add(__lowerCamelCase				)

                              # n=2
                              lowercase_     =      x_num * x_num * y_num * y_num
                              lowercase_     =      (
                                  x_den * x_den * y_num * y_num + x_num * x_num * y_den * y_den
                              )
                              if is_sq(__lowerCamelCase				) and is_sq(__lowerCamelCase				):
                                    lowercase_     =      int(sqrt(__lowerCamelCase				)				)
                                    lowercase_     =      int(sqrt(__lowerCamelCase				)				)
                                    lowercase_     =      gcd(__lowerCamelCase ,		__lowerCamelCase				)
                                    z_num //= hcf
                                    z_den //= hcf
                                    if 0 < z_num < z_den <= order:
                                          lowercase_     =      add_three(
                                              __lowerCamelCase ,		__lowerCamelCase ,		__lowerCamelCase ,		__lowerCamelCase ,		__lowerCamelCase ,		__lowerCamelCase				)
                                          unique_s.add(__lowerCamelCase				)

      for num, den in unique_s:
            total += Fraction(__lowerCamelCase ,		__lowerCamelCase				)

      return total.denominator + total.numerator


if __name__ == "__main__":
       print(F'''{solution() = }''')







'''simple docstring'''

from __future__ import annotations


def __a (	__lowerCamelCase			:						int | str				)	->							bool:
      '''simple docstring'''


      lowercase_     =      str(__lowerCamelCase				)
      return n == n[::-1]


def __a (	__lowerCamelCase			:						int = 1_000_000				)	->							Optional[int]:
      '''simple docstring'''


      lowercase_     =      0

      for i in range(1 ,		__lowerCamelCase				):
            if is_palindrome(__lowerCamelCase				) and is_palindrome(bin(__lowerCamelCase				).split("b"				)[1]				):
                  total += i
      return total


if __name__ == "__main__":
       print(solution(int(str(input().strip()))))






