Problem:
Score : 300 points

Problem Statement

Find \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.

Here \gcd(a,b,c) denotes the greatest common divisor of a, b, and c.

Constraints

1 \leq K \leq 200

K is an integer.

Input

Input is given from Standard Input in the following format:

K

Output

Print the value of \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.

Sample Input 1

2

Sample Output 1

9

\gcd(1,1,1)+\gcd(1,1,2)+\gcd(1,2,1)+\gcd(1,2,2)
+\gcd(2,1,1)+\gcd(2,1,2)+\gcd(2,2,1)+\gcd(2,2,2)
=1+1+1+1+1+1+1+2=9

Thus, the answer is 9.

Sample Input 2

200

Sample Output 2

10813692

Solution in Fortran (GNU Fortran 9.2.1) (judge verdict: Wrong Answer)

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=1, K
    do c=1, K
      call gcd(a,b,c,G,primenumber,countprime)
      count=count+G
    end do
  end do
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
    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, 10
      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(:)
    integer(4), intent(out) :: vecout(:)
    integer(4) ::  k, l , count, m, ap



    vecout(1)=1

    do k=2, 10
      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