Last active
November 13, 2015 13:32
-
-
Save nekoTheShadow/a8887bf055d33f786d56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; bを固定したときの(a,c)の組み合わせを数える | |
; (count-ac-combs 3) => 3 [(a,c) = (1,1)(1,2)(2,1)] | |
(define (count-ac-combs b) | |
(let* ((t (quotient (* b b) 4)) | |
(comb-a<c | |
(let loop ((a 1) (sum 0)) | |
(if (> (* a (+ a 1)) t) | |
sum | |
(loop (+ a 1) (+ sum (- (quotient t a) a)))))) | |
(comb-a=c (inexact->exact (floor (sqrt t))))) | |
(+ (* comb-a<c 2) comb-a=c))) | |
; 1 <= b <= m を満たす(a,b,c)の組み合わせの総数を数える | |
; (count-abc-combs 3) => 4 [(a,b,c) = (1,2,1)(1,3,1)(1,3,2)(2,3,1)] | |
(define (count-abc-combs m) | |
(let loop ((b 1) (sum 0)) | |
(if (> b m) | |
sum | |
(loop (+ b 1) (+ sum (count-ac-combs b)))))) | |
; == main == | |
; 入力された数字をmとして、1 <= b <= m を満たす(a,b,c)の組み合わせの総数を数える | |
(display (count-abc-combs 3000)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment