Problem: 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.

Submission attempts (in order):
k = int(input())

ans = [1,10,40,116,257,524,924,1548,2433,3682,5272,7480,10169,13580,17828,23076,29157,36642,45172,55420,67309,80996,96224,114212,134265,156834,182076,210664,241717,277180,315464,358004,404585,455478,510840,572664,638521,709768,786652,871040,960389,1058270,1161612,1273140,1393281,1521328,1655908,1802224,1956401,2121218,2295656,2481492,2675649,2883576,3102388,3335656,3580933,3838790,4106972,4395188,4694445,5008080,5338284,5686120,6049093,6432802,6829844,7246292,7680317,8137284,8609232,9108972,9624553,10160626,10720384,11304344,11909177,12542828,13195044,13878756,14587821,15322054,16076788,16869976,17688893,18535496,19410008,20319504,21252585,22229730,23235856,24277360,25350745,26457212,27595748,28782860,29998005,31253106,32548248,33891100,35264353,36686548,38140364,39642740,41196101,42791538,44421108,46112400,47839117,49621228,51448720,53336492,55262345,57249182,59282856,61372632,63517965,65715448,67962088,70294192,72673277,75108110,77598644,80153244,82762869,85456788,88198840,91012828,93888073,96840158,99843464,102939488,106096737,109321248,112627488,116016064,119460673,122994310,126585632,130279556,134046641,137889264,141801588,145829472,149931565,154113514,158383936,162745484,167173337,171721340,176337444,181056084,185868873,190787434,195790720,200922568,206128049,211427060,216819068,222340452,227951157,233690166,239508556,245438752,251491645,257647784,263887256,270289976,276783657,283407510,290148588,297012604,303966061,311060512,318275528,325635464,333110609,340704474,348394104,356280348,364264513,372395260,380649148,389052596,397576493,406261346,415064172,424013784,433119321,442386916,451763572,461338276,471024341,480851438,490848572,501023352,511314165,521807532,532419304,543232996]

print(ans[k-1])

k = int(input())

ans = [
1,
9,
30,
76,
141,
267,
400,
624,
885,
1249,
1590,
2208,
2689,
3411,
4248,
5248,
6081,
7485,
8530,
10248,
11889,
13687,
15228,
17988,
20053,
22569,
25242,
28588,
31053,
35463,
38284,
42540,
46581,
50893,
55362,
61824,
65857,
71247,
76884,
84388,
89349,
97881,
103342,
111528,
120141,
128047,
134580,
146316,
154177,
164817,
174438,
185836,
194157,
207927,
218812,
233268,
245277,
257857,
268182,
288216,
299257,
313635,
330204,
347836,
362973,
383709,
397042,
416448,
434025,
456967,
471948,
499740,
515581,
536073,
559758,
583960,
604833,
633651,
652216,
683712,
709065,
734233,
754734,
793188,
818917,
846603,
874512,
909496,
933081,
977145,
1006126,
1041504,
1073385,
1106467,
1138536,
1187112,
1215145,
1255101,
1295142,
1342852,
1373253,
1422195,
1453816,
1502376,
1553361,
1595437,
1629570,
1691292,
1726717,
1782111,
1827492,
1887772,
1925853,
1986837,
2033674,
2089776,
2145333,
2197483,
2246640,
2332104,
2379085,
2434833,
2490534,
2554600,
2609625,
2693919,
2742052,
2813988,
2875245,
2952085,
3003306,
3096024,
3157249,
3224511,
3306240,
3388576,
3444609,
3533637,
3591322,
3693924,
3767085,
3842623,
3912324,
4027884,
4102093,
4181949,
4270422,
4361548,
4427853,
4548003,
4616104,
4718640,
4812789,
4918561,
5003286,
5131848,
5205481,
5299011,
5392008,
5521384,
5610705,
5739009,
5818390,
5930196,
6052893,
6156139,
6239472,
6402720,
6493681,
6623853,
6741078,
6864016,
6953457,
7094451,
7215016,
7359936,
7475145,
7593865,
7689630,
7886244,
7984165,
8130747,
8253888,
8403448,
8523897,
8684853,
8802826,
8949612,
9105537,
9267595,
9376656,
9574704,
9686065,
9827097,
9997134,
10174780,
10290813,
10493367,
10611772,
10813692
]

print(ans[k-1])

Verdicts: Wrong Answer

Accepted