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: Accepted)

program ABC162C
    implicit none
    integer(8)::i,j,k,N,ans
    read*,N
    ans=0

    do i=1,N
        do j=1,N
            do k=1,N
                ans=ans+gcd(i,gcd(j,k))
            end do
        end do
    end do

    print'(i0)',ans
contains
    integer(8) function gcd(a,b)
        implicit none
        integer(8),intent(IN)::a,b
        integer(8)::l,m,n

        m=a
        n=b

        do
            l=mod(m,n)
            if(l==0)then
                exit
            end if
            m=n
            n=l
        end do

        gcd=n
        return
    end function gcd
end program ABC162C