Created
February 24, 2014 01:05
-
-
Save swuecho/9179971 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
发信人: zhaowei2008 (zhaowei), 信区: JobHunting | |
标 题: 问个题目: 从1-n 中找出k, 使得 k=a^2 +b^2 (a b 为整数) | |
发信站: BBS 未名空间站 (Sun Feb 23 15:31:23 2014, 美东) | |
问个题目: 从1-n 中找出k, 使得 k=a^2 +b^2 (a b 为整数) | |
有好的算法吗? | |
(defn find-k [n] | |
(let [s (int (Math/sqrt n))] | |
(distinct | |
(for [a (range 1 (inc s)) | |
b (range a (inc s)) | |
:let [c (+ (* a a) (* b b))] | |
:when (<= c n)] | |
c)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment