#lang racket

(define (solve K)
  (define (c-iter ab c)
    (if (> c K)
        0
        (+ (gcd ab c) (c-iter ab (+ c 1)))))
  (define (b-iter a b)
    (if (> b K)
        0
        (+ (c-iter (gcd a b) 1) (b-iter a (+ b 1)))))
  (define (a-iter a)
    (if (> a K)
        0
        (+ (b-iter a 1) (a-iter (+ a 1)))))
  (a-iter 1))

(let ([K (read)])
  (display (solve K)))
