(define (expt-mod a n) (let loop ([k 1] [ak a] [ls '()]) ;; a^1 a^2 a^4のリスト (if (<= k n) (loop (* k 2) (remainder (* ak ak) 1000000007) (cons (cons k ak) ls)) (let loop2 ([ls ls] [n n] [an 1]) (cond [(zero? n) an] [(> (caar ls) n) (loop2 (cdr ls) n an)] [else (loop2 (cdr ls) (- n (caar ls)) (remainder (* an (cdar ls)) 1000000007))]))))) (print (expt-mod (* (read) (read) (read)) (expt 2 (read))))