#lang racket

(define (square x)
  (* x x))

(define (pow b n)
  (cond ([= n 0] 1)
        ([even? n] [square (pow b (/ n 2))])
        (else [* b (pow b (- n 1))])))

(define mod (+ (pow 10 9) 7))

(define (solve N K)
  (let ([table (make-vector (+ K 1) 0)])
    (define (j-iter j total step)
      (if (> j K)
          total
          (j-iter (+ j step) (- total (vector-ref table j)) step)))
    (define (iter i total)
      (if (zero? i)
          (modulo total mod)
          (begin
            (vector-set! table i (pow (floor (/ K i)) N))
            (let ([j (j-iter (* i 2) (vector-ref table i) i)])
              (vector-set! table i j)
              (iter (- i 1) (+ total (* i j)))))))
    (iter K 0)))

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