相关疑难解决方法(0)

Haskell性能优化

我正在编写代码来查找第n个Ramanujan-Hardy号码.Ramanujan-Hardy数字定义为

n = a^3 + b^3 = c^3 + d^3
Run Code Online (Sandbox Code Playgroud)

意味着n可以表示为两个立方体的总和.

我在haskell中编写了以下代码:

-- my own implementation for cube root. Expected time complexity is O(n^(1/3))
cube_root n = chelper 1 n
                where
                        chelper i n = if i*i*i > n then (i-1) else chelper (i+1) n

-- It checks if the given number can be expressed as a^3 + b^3 = c^3 + d^3 (is Ramanujan-Hardy number?)
is_ram n = length [a| a<-[1..crn], b<-[(a+1)..crn], c<-[(a+1)..crn], d<-[(c+1)..crn], a*a*a + b*b*b == n …
Run Code Online (Sandbox Code Playgroud)

algorithm optimization haskell

4
推荐指数
1
解决办法
337
查看次数

标签 统计

algorithm ×1

haskell ×1

optimization ×1