from math import gcd

K = int(eval(input()))

total = 0

for a in range(1,K+1):

    for b in range(1,K+1):

        for c in range(1,K+1):

            total+=gcd(gcd(a,b),c)

print(total)
import sys

from math import gcd

input = sys.stdin.readline

def main():

    K = int(eval(input()))

    total = 0

    for a in range(1,K+1):

        for b in range(1,K+1):

            tmp = gcd(a,b)

            for c in range(1,K+1):

                total+=gcd(tmp,c)

    print(total)

if __name__ == '__main__':

    main()
from math import gcd

K = int(eval(input()))
total = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            total += gcd(gcd(a, b), c)
print(total)

import sys
from math import gcd

input = sys.stdin.readline


def main():
    K = int(eval(input()))
    total = 0
    for a in range(1, K + 1):
        for b in range(1, K + 1):
            tmp = gcd(a, b)
            for c in range(1, K + 1):
                total += gcd(tmp, c)
    print(total)


if __name__ == "__main__":
    main()

+import sys -K = int(eval(input())) -total = 0 -for a in range(1, K + 1): -    for b in range(1, K + 1): -        for c in range(1, K + 1): -            total += gcd(gcd(a, b), c) -print(total) +input = sys.stdin.readline + + +def main(): +    K = int(eval(input())) +    total = 0 +    for a in range(1, K + 1): +        for b in range(1, K + 1): +            tmp = gcd(a, b) +            for c in range(1, K + 1): +                total += gcd(tmp, c) +    print(total) + + +if __name__ == "__main__": +    main()