program problemC
  implicit none

integer(4) :: K, a,b,c , count, G , n , countprime, number(200), m, l
integer(4), allocatable :: primenumber(:), pvec(:)
integer(4) :: input

 read(*,*) K


do n=1,200
  number(n)=n
end do

do n=2, 200
  if (number(n)/=0) then
    do m=n+1, 200
      if (number(m)/=0) then
        if (mod(number(m),n)==0) then
          number(m)=0
        end if
      end if
    end do
  end if
end do

countprime=0
do n=1, 200
      if (number(n)/=0) then
        countprime=countprime+1
      end if
end do

allocate(primenumber(countprime), pvec(countprime))



countprime=0
do n=1, 200
      if (number(n)/=0) then
        countprime=countprime+1
        primenumber(countprime)=number(n)
      end if
end do


count=0
do a=1, K
  do b=a+1, K
    do c=b+1, K
      call gcd(a,b,c,G,primenumber,countprime)
      count=count+G
    end do
  end do
end do

count=count*2
do a=1,K
call gcd(a,b,c,G,primenumber,countprime)
count=count+G
end do




write(*,*) count


deallocate(primenumber,pvec)

stop
contains
  subroutine gcd(a,b,c,G,vecin,n)
    implicit none

    integer(4), intent(in) :: a,b,c
    integer(4), intent(out) :: G
    integer(4), intent(in) :: vecin(n),n
    integer(4) :: avec(n), bvec(n),cvec(n),k

    call factor(a,vecin,n,avec)
    call factor(b,vecin,n,bvec)
    call factor(c,vecin,n,cvec)

    G=1
    do k=1, n
      if (avec(k)==0 .or. bvec(k)==0 .or. cvec(k)==0) then
        G=G*1
      else
        G=G*(vecin(k)**min(avec(k),bvec(k),cvec(k)))
      end if
    end do


  end subroutine gcd

  subroutine factor(a,vecin, n,vecout)
    implicit none

    integer(4), intent(in) :: a,n
    integer(4), intent(in) :: vecin(n)
    integer(4), intent(out) :: vecout(n)
    integer(4) ::  k, l , count, m, ap



    vecout(1)=1

    do k=2, n
      l=0
      count=0
      ap=a
      if (a>=vecin(k)) then
        do while (l==0)
          l=mod(ap,vecin(k))
          if (l==0) then
            count=count+1
            ap=ap/vecin(k)
          end if
        end do
        vecout(k)=count
      end if
      if (a<vecin(k)) then
        vecout(k)=0
      end if
    end do




  end subroutine factor

end program
