P31 (**) Determine whether a given integer number is prime.
来源:互联网 发布:知豆汽车销量 编辑:程序博客网 时间:2024/06/11 03:54
问题描述
sash> (prime? 7) -> #t
解法
素数是大于1且约数只有1和其本身的整数。实现算法很多,下面是比较简单的一种。
(define prime? (lambda (n) (cond [(< n 2) #f] [(= n 2) #t] [(zero? (floor-remainder n 2)) #f] [else (let f ([i 3]) (cond [(> (* i i) n) #t] [else (if (zero? (floor-remainder n i)) #f (f (+ i 2)))]))])))
1 0
- P31 (**) Determine whether a given integer number is prime.
- 3、Determine whether an integer is a palindrome
- isa - Determine whether input is object of given class matlab
- 【LeetCode】 Determine whether an integer is a palindrome. Do this without extra space
- Determine whether an integer is a palindrome. Do this without extra space.
- Determine whether an integer is a palindrome. Do this without extra space.
- Determine whether an integer is a palindrome. Do this without extra space.
- Find whether a given number is a power of 4 or not
- CareerCup Find whether a given number is a perfect square or not.(Addition and Subtraction only)
- To Determine a Prime Number
- Given a number m, how to decide whether this m is in the matrix
- Given an integer, write a function to determine if it is a power of two.
- Given an integer, write a function to determine if it is a power of two
- leetCode Given an integer (signed 32 bits), write a function to check whether it is a power of 4
- Judge whether a telephone number is right or not
- 【Leetcode】Given a binary tree, check whether it is a mirror of itself
- Geeks - Check whether a given graph is Bipartite or not 二分图检查
- P33 (*) Determine whether two positive integer numbers are coprime.
- 今日开讲—— easyui-combobox动态赋值
- CocoaPods详解之----使用篇
- IOS 世界标准时间UTC /GMT 转为当前系统时区对应的时间
- 承接云购类网站完整建立工作。
- BZOJ4385/POI2015Wilcze doły
- P31 (**) Determine whether a given integer number is prime.
- java设计模式——创建型之工厂三兄弟(3)
- 安装MySQL 5后无法启动(不能Start service)解决方法小结
- nyoj 171 聪明的kk
- jnaerator命令行生成bridj的包(java调用c++动态链接库)
- android自定义控件(一),组合控件Titlebar的定制
- 简单的时间片轮转多道程序内核代码分析
- [POJ] 1201 Intervals [差分约束]
- [小白见解]关于iOS小白开发中的字典转模型数据