博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HackerRank(FP) - The Sums of Powers
阅读量:4671 次
发布时间:2019-06-09

本文共 984 字,大约阅读时间需要 3 分钟。

In Haskell. Two points: 1. pruning 2. Int suffers from overflow. Integer it is.

getPowerSum :: Integer -> [Integer] -> Integer -> IntegergetPowerSum _ [] _           = 0getPowerSum tgt cand start = case compare tgt start of                                                             EQ     -> 1                                LT    -> 0                                GT  ->     let newCand = filter (>start) cand in                                        let newTgt  = tgt - start in                                        sum $ map (getPowerSum newTgt newCand) newCandgetPowerSumWays :: Integer -> Integer -> [Integer]getPowerSumWays x n = let cand = [i^n | i <- [1..x], (i ^ n) <= x] in                      map (getPowerSum x cand) cand                                            -- Main --main = do    sx <- getLine    sn <- getLine    let x = read sx :: Integer    let n = read sn :: Integer    print $ sum $ getPowerSumWays x n

转载于:https://www.cnblogs.com/tonix/p/4310074.html

你可能感兴趣的文章
Navicat远程连接阿里云服务器的mysql
查看>>
黑客dos命令大全
查看>>
https soap链接示例
查看>>
八LWIP学习笔记之用户编程接口(NETCONN)
查看>>
Git Day02,工作区,暂存区,回退,删除文件
查看>>
Windows Phone 7 Coding4Fun控件简介
查看>>
Nginx 常用命令总结
查看>>
hall wrong behavior
查看>>
Markdown test
查看>>
Collection集合
查看>>
int最大值+1为什么是-2147483648最小值-1为什么是2147483647
查看>>
【C++】const在不同位置修饰指针变量
查看>>
github新项目挂历模式
查看>>
编写jquery插件
查看>>
敏捷开发笔记
查看>>
神秘海域:顶级工作室“顽皮狗”成长史(下)
查看>>
C++指针、引用知多少?
查看>>
services 系统服务的启动、停止、卸载
查看>>
Fiddler 网页采集抓包利器__手机app抓包
查看>>
Number and String
查看>>