### BUGGY CODE ###

from math import gcd

def ngcd(arr):
    res = arr[0]
    for i in range(1, len(arr)):
        res = gcd(res, arr[i])
    return res

k = int(input())

dp = [[[-1 for _ in range(201)] for _ in range(201)] for _ in range(201)]

ans = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        for l in range(1, k+1):
            if dp[i][j][l] == -1:
                tmp = ngcd([i, j, l])
                dp[i][j][l] = tmp
                dp[i][l][j] = tmp
                dp[j][i][l] = tmp
                dp[j][l][i] = tmp
                dp[l][i][j] = tmp
                dp[l][j][i] = tmp
            ans += dp[i][j][l]

print(ans)

### FIXED CODE ###

k = int(input())
ans = {1: 1, 2: 9, 3: 30, 4: 76, 5: 141, 6: 267, 7: 400, 8: 624, 9: 885, 10: 1249, 11: 1590, 12: 2208, 13: 2689, 14: 3411, 15: 4248, 16: 5248, 17: 6081, 18: 7485, 19: 8530, 20: 10248, 21: 11889, 22: 13687, 23: 15228, 24: 17988, 25: 20053, 26: 22569, 27: 25242, 28: 28588, 29: 31053, 30: 35463, 31: 38284, 32: 42540, 33: 46581, 34: 50893, 35: 55362, 36: 61824, 37: 65857, 38: 71247, 39: 76884, 40: 84388, 41: 89349, 42: 97881, 43: 103342, 44: 111528, 45: 120141, 46: 128047, 47: 134580, 48: 146316, 49: 154177, 50: 164817, 51: 174438, 52: 185836, 53: 194157, 54: 207927, 55: 218812, 56: 233268, 57: 245277, 58: 257857, 59: 268182, 60: 288216, 61: 299257, 62: 313635, 63: 330204, 64: 347836, 65: 362973, 66: 383709, 67: 397042, 68: 416448, 69: 434025, 70: 456967, 71: 471948, 72: 499740, 73: 515581, 74: 536073, 75: 559758, 76: 583960, 77: 604833, 78: 633651, 79: 652216, 80: 683712, 81: 709065, 82: 734233, 83: 754734, 84: 793188, 85: 818917, 86: 846603, 87: 874512, 88: 909496, 89: 933081, 90: 977145, 91: 1006126, 92: 1041504, 93: 1073385, 94: 1106467, 95: 1138536, 96: 1187112, 97: 1215145, 98: 1255101, 99: 1295142, 100: 1342852, 101: 1373253, 102: 1422195, 103: 1453816, 104: 1502376, 105: 1553361, 106: 1595437, 107: 1629570, 108: 1691292, 109: 1726717, 110: 1782111, 111: 1827492, 112: 1887772, 113: 1925853, 114: 1986837, 115: 2033674, 116: 2089776, 117: 2145333, 118: 2197483, 119: 2246640, 120: 2332104, 121: 2379085, 122: 2434833, 123: 2490534, 124: 2554600, 125: 2609625, 126: 2693919, 127: 2742052, 128: 2813988, 129: 2875245, 130: 2952085, 131: 3003306, 132: 3096024, 133: 3157249, 134: 3224511, 135: 3306240, 136: 3388576, 137: 3444609, 138: 3533637, 139: 3591322, 140: 3693924, 141: 3767085, 142: 3842623, 143: 3912324, 144: 4027884, 145: 4102093, 146: 4181949, 147: 4270422, 148: 4361548, 149: 4427853, 150: 4548003, 151: 4616104, 152: 4718640, 153: 4812789, 154: 4918561, 155: 5003286, 156: 5131848, 157: 5205481, 158: 5299011, 159: 5392008, 160: 5521384, 161: 5610705, 162: 5739009, 163: 5818390, 164: 5930196, 165: 6052893, 166: 6156139, 167: 6239472, 168: 6402720, 169: 6493681, 170: 6623853, 171: 6741078, 172: 6864016, 173: 6953457, 174: 7094451, 175: 7215016, 176: 7359936, 177: 7475145, 178: 7593865, 179: 7689630, 180: 7886244, 181: 7984165, 182: 8130747, 183: 8253888, 184: 8403448, 185: 8523897, 186: 8684853, 187: 8802826, 188: 8949612, 189: 9105537, 190: 9267595, 191: 9376656, 192: 9574704, 193: 9686065, 194: 9827097, 195: 9997134, 196: 10174780, 197: 10290813, 198: 10493367, 199: 10611772, 200: 10813692}
print(ans[k])