20/09/24 02:11:02.31 tZusWsqn.net
まともに数え上げたのもΣも漸化式も一致
一般項はBessel関数使えばできるけどそれ以外じゃ無理だろな
import Data.Ratio
c n k = div (product [n-k+1..n]) (product [1..k])
f n = product [1..n]
chooseNext (x,y)
= [(x ++ [(a,b)], [c | c<- y, c/=a,c/=b]) |
a <- y,
b <- y, a +1 < b,
True]
makePairings n = map fst $ (!! n) $ iterate (>>= chooseNext) [([],[1..2*n])]
countPairings n = (flip div (product [1..n])) $ length $ makePairings n
sumExpress n = flip div ((2^n)*(f n)) $sum [(c n k)*(-2)^k*(f $ 2*n-k) | k<-[0..n]]
recurseExpress = map head $ iterate (\[ao,an,n] -> [an,(2*n-1)*an+ao,n+1]) [0,1,3]
p = ( (f 26)*2^26*(recurseExpress!!25)) %( f 52)
main = do
print $ [countPairings n | n<- [1..6]]
print $ [sumExpress n | n<-[1..6]]
print $ take 6 recurseExpress
print $ p
print $ fromRational p
[0,1,5,36,329,3655]
[0,1,5,36,329,3655]
[0,1,5,36,329,3655]
6203831733479827686859697128543 % 170298737928189192841498811