[Algorithm] Finding all factors of a number
12's factors are: {1,2,3,4,6,12}
function factors (n) {
let list = [];
for (let i = 1; i < Math.sqrt(n); i++) {
if (n % i === 0) {
list.push(i);
if (i !== Math.sqrt(n)) {
list.push(n / i);
}
}
}
return list;
}
factors(12) // [ 1, 12, 2, 6, 3, 4 ]
[Algorithm] Finding all factors of a number的更多相关文章
- [Algorithm] Finding Prime numbers - Sieve of Eratosthenes
Given a number N, the output should be the all the prime numbers which is less than N. The solution ...
- [Algorithm] 4. Ugly Number II
Description Ugly number is a number that only havefactors 2, 3 and 5. Design an algorithm to find th ...
- 2014辽宁ACM省赛 Prime Factors
问题 L: Prime Factors 时间限制: 1 Sec 内存限制: 128 MB [提交][状态][论坛] 题目描写叙述 I'll give you a number , please te ...
- poj1142.Smith Number(数学推导)
Smith Number Time Limit: 1 Sec Memory Limit: 64 MB Submit: 825 Solved: 366 Description While skimm ...
- WUSTOJ 1332: Prime Factors(Java)
题目链接:1332: Prime Factors Description I'll give you a number , please tell me how many different prim ...
- Must practice programming questions in all languages
To master any programming languages, you need to definitely solve/practice the below-listed problems ...
- [C1] Andrew Ng - AI For Everyone
About this Course AI is not only for engineers. If you want your organization to become better at us ...
- Design and Analysis of Algorithms_Divide-and-Conquer
I collect and make up this pseudocode from the book: <<Introduction to the Design and Analysis ...
- Working Set缓存算法(转)
为了加深对缓存算法的理解,特转此篇,又由于本文内容过多,故不做翻译,原文地址Working Set页面置换算法 In the purest form of paging, processes are ...
随机推荐
- 数据排序 sort
排序命令: 常和管道进行协作的命令 -sort (默认使用字符的第一个字符进行排序) -n 按数字排序 -r 反序排序 -o 结果 输出到文件 -t 分隔符 (sort -n -t &qu ...
- hdu 6601 区间条件极值 - 区间 最大 三角形周长
题目传送门//res tp hdu 目的 对长度为n的区间,给定q个子区间,求其元素能构成三角形的最大周长.有多组测试. n 1e5 q 1e5 ai [1,1e9] (i∈[1,n]); 数据结构 ...
- Codeforces Round #309 (Div. 1)
A. Kyoya and Colored Balls 大意: 给定$k$种颜色的球, 第$i$种颜色有$c_i$个, 一个合法的排列方案满足最后一个第$i$种球的下一个球为第$i+1$种球, 求合法方 ...
- MySQL 存储引擎的类型以及选择
针对MySQL,数据最终以什么样的形式保存?以及数据保存在硬盘的什么位置? 1.MySQL的存储引擎 MySQL属于数据管理系统(DBMS),其中包括数据库,负责存储数据:还有数据库访问管理的接口系统 ...
- Java lesson17 homework
package lesson17; /**1. 创建自定义类Triangle包含如下属性: 最小夹角 a(整型.单位度) 最大夹角 b(整型.单位度) 编写构造方法包含两个参数(夹角),并根据参数计算 ...
- 给没有连接因特网的centos使用yum安装其他软件(转)
https://blog.csdn.net/bbg221/article/details/78360618 在centos上,使用yum安装软件很方便,比如安装gcc,java等, 但是在没有网络的情 ...
- HTML之美化盒子
1. 美化盒子 1.1. 美化文本 1.1.1. 字体大小[font-size]: 字符框的高度,可继承,默认值medium,16px.基准字号:浏览器设置的默认字体大小,通 ...
- 输出指令(echo指令和printf 命令)
Shell echo命令 Shell 的 echo 指令与 PHP 的 echo 指令类似,都是用于字符串的输出.命令格式: echo string 您可以使用echo实现更复杂的输出格式控制. 1. ...
- 线程----code
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- Linux Shell Web超级终端工具shellinabox
Shell是Linux内核应用程序,是指“为使用者提供操作界面”的软件,也是命令解析器,它类似于Windows操作系统DOS下的cmd.exe应用程序.它接收用户命令,然后调用相应的应用程序,用户一般 ...