program main
  
  implicit none
  integer :: a, b, c, ll, ss, tmp ,ab
  integer :: ans, k
  integer,allocatable :: aa(:,:)
  
  read(*,*) k
  allocate(aa(200,200))
  
  aa = 0 
  ans = 0
  do a = 1, k
    do b = 1, k
      if( a > b) then
        ll = a
        ss = b
      else
        ll = b
        ss = a
      end if
      do
        tmp = ss
        ss = mod(ll,ss)
        ll = tmp
        if( ss == 0 ) then
          aa(a,b) = tmp
          exit
        end if
      end do
    end do
  end do

  do a = 1, k
    do b = 1, k
      ll = aa(a,b)
      do c = 1, k
        ans = ans + aa(ll,c)
      end do
    end do
  end do
  print*, ans
  
  
end program main
