问题描写叙述:

Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n).

If d(a) = b and d(b) = a, where a  b, then a and b are
an amicable pair and each of a and b are called amicable numbers.

For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; therefore d(220) = 284. The proper divisors of 284 are 1, 2, 4, 71 and 142; so d(284) = 220.

Evaluate the sum of all the amicable numbers under 10000.

实现:

(function(){

var factor = function (n){
var arr = new Array();
for(var i = 1;i < n; i++)
{
if(n%i == 0 && arr.indexOf(i) == -1)
arr.push(i);
}
return arr;
} var sumArr = function(arr){
var sum = 0 ; for(var i = 0 ; i < arr.length; i++)
sum += arr[i]; return sum ;
} for(var i = 2;i< 10000; i++)
{
var r1 = sumArr(factor(i));
var r2 = sumArr(factor(r1)); if(i == r2 && i != r1)
console.log("num1 : " + i + ", num2 : " + r1);
} })();

Amicable numbers -- Javascript 实现的更多相关文章

  1. (Problem 21)Amicable numbers

    Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into ...

  2. Eloquent JavaScript #01# values

    When action grows unprofitable, gather information; when information grows unprofitable, sleep.      ...

  3. Javascript——概述 && 继承 && 复用 && 私有成员 && 构造函数

    原文链接:A re-introduction to JavaScript (JS tutorial) Why a re-introduction? Because JavaScript is noto ...

  4. JavaScript Basics_Fundamentals Part 1_Numbers

    Javascript Numbers 知识描述:JavaScript 只有一种数字类型,即数字(Number).数字可以带小数点,也可以不带,也就是整数和小数. 数字可以带小数点,也可以不带: Exa ...

  5. JavaScript 转换数字为整数的方法

    本文将会列举并说明JavaScript 把一个number(或者numerical的对象)转换成一个整数相关方法. 使用parseInt parseInt的语法如下:parseInt(string, ...

  6. JavaScript- The Good Parts CHAPTER 2

    I know it well:I read it in the grammar long ago.—William Shakespeare, The Tragedy(悲剧:灾难:惨案) of Titu ...

  7. MongoDB:The Definitive Guide CHAPTER 2 Getting Started

    MongoDB is very powerful, but it is still easy to get started with. In this chapter we’ll introduce ...

  8. PE刷题记

    PE 中文翻译 最喜欢做这种很有意思的数学题了虽然数学很垃圾 但是这个网站的提交方式好鬼畜啊qwq 1.Multiples of 3 and 5 直接枚举 2.Even Fibonacci numbe ...

  9. Problem 21

    Problem 21 https://projecteuler.net/problem=21 Let d(n) be defined as the sum of proper divisors of  ...

随机推荐

  1. CSS预处理器——Sass、LESS和Stylus实践【未删减版】

    http://www.w3cplus.com/css/css-preprocessor-sass-vs-less-stylus-2.html

  2. BOM对象

    每一个frames都有自己的window对象,也就是每个frames都有自己的全局对象,它们之前是相互独立的,包括各自独立的本地对象,top.Object !== top.frames[0].Obje ...

  3. sass学习--安装ruby

    1.下载ruby:https://rubyinstaller.org/downloads/ 2.安装完ruby之后,在开始菜单中,找到刚才我们安装的ruby,打开Start Command Promp ...

  4. lvs学习笔记

    本人身为一个网工,最近一直在工作中学习linux的相关知识.前短时间通过自查资料学习了lvs的相关内容,摘录部分整理后和大家分享,内容较多,较琐碎,望见谅!!! LVS 从Linux内核版本2.6起, ...

  5. jQuery实现checkbox即点即改,批量计数,以及中间遇到的坑

    最近要用jQuery实现一个批量删除操作,效果如下图 最终页面page.html,此页面使用了bootstrap和jQuery,如果没有需要下载一下 <!DOCTYPE html> < ...

  6. 在ASP.NET开发中一些单词的标准缩写

    有些词可能共用一些缩写.带星号的缩写或词来源于PeopleSoft标准. The following standard word abbreviations should be used in nam ...

  7. Python之mysql数据库更新表数据接口实现

    昨天,因为项目需求要添加表的更新接口,来存储预测模型训练的数据. 先码为敬~~~~~~~ # -*- coding: utf-8 -*- import pymysql import settings ...

  8. javaBean实体包区分

    随着软件工程结构越来越复杂,单一的entity实体包无法满足业务需要,可以采取PO,BO,DTO结构来分类实体. PO (Persistent Object):与数据库表数据关联的实体. BO(Bus ...

  9. 32.Linux-2440下的DMA驱动(详解)

    DMA(Direct Memory Access) 即直接存储器访问, DMA 传输方式无需 CPU 直接控制传输,通过硬件为 RAM .I/O 设备开辟一条直接传送数据的通路,能使 CPU 的效率大 ...

  10. python数据结构与算法篇:排序

    1.冒泡排序(英语:Bubble Sort) 它重复地遍历要排序的数列,一次比较两个元素,如果他们的顺序错误就把他们交换过来.遍历数列的工作是重复地进行直到没有再需要交换,也就是说该数列已经排序完成. ...