Buggy python submission (verdict: Time Limit Exceeded):
import math
k = int(input())
x = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            x += math.gcd(math.gcd(a, b), c)
print(x)


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