- 浏览: 37035 次
- 性别:
- 来自: 杭州
最新评论
Problem 21 05 July 2002 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
package com.yao; import java.util.HashSet; import java.util.Set; /** * Created by IntelliJ IDEA. * User: shuimuqinghua77 * Date: 12-3-11 * Time: 下午7:55 */ public class Problem21 { public static void main(String[] args) { int top=10000; int result=0; Set<Integer> invalid=new HashSet<Integer>(); long start=System.currentTimeMillis(); for(int i=2;i<top;i++){ if(invalid.contains(i)) continue; int sum=sum(i); if(sum<=top&&sum!=i&&i==sum(sum)){ invalid.add(sum); result+=(sum+i); System.out.println("("+i+","+sum+")"); } } long end=System.currentTimeMillis(); System.out.println(end-start); System.out.println(result); } private static int sum(int n) { if(n==1)return 0; int sum=1; int middle=(int)Math.sqrt(n); for(int j=2;j<=middle;j++){ if(n%j==0){ int k=n/j; if(k==j) sum+=j; else sum+=(k+j); } } return sum; } }
发表评论
-
Problem26
2013-02-06 17:08 870A unit fraction contains 1 in t ... -
Problem25
2012-04-26 16:33 887package com.yao.Algorithms; ... -
Problem24
2012-04-26 14:12 787package com.yao.Algorithms; ... -
Problem23
2012-03-18 13:29 906A perfect number is a number fo ... -
Problem22
2012-03-17 23:13 774Using names.txt (right click an ... -
Problem20
2011-12-15 14:09 806package com.yao.shuimu.euler; ... -
Problem19
2011-12-09 14:07 720package com.shui.mu.yao.io.algo ... -
Problem18/Problem67
2011-12-04 20:20 900package com.yao.Algorithms; ... -
Problem16
2011-12-02 15:32 423package com.shui.mu.yao.io.algo ... -
Problem15
2011-11-29 23:28 538package com.yao.Algorithms; ... -
Problem14
2011-11-29 11:37 712package com.shui.mu.yao.io.algo ... -
Problem13_1
2011-11-21 14:07 593package yao.taobao.jj; publi ... -
Problem13
2011-11-19 23:51 572package com.yao.Algorithms; ... -
Problem12
2011-11-07 20:04 714package com.shui.mu.yao.io.algo ... -
Problem11
2011-11-06 19:38 1202package com.yao.Algorithms; ... -
Problem10
2011-11-03 20:14 417package com.shui.mu.yao.io.algo ... -
Problem9
2011-11-03 16:04 753package com.shui.mu.yao.io.algo ... -
Problem8
2011-11-03 12:38 594package com.shui.mu.yao.io.algo ... -
Problem7
2011-11-03 11:25 461package com.shui.mu.yao.io.algo ...
相关推荐
21. The maximum emission rate is 500 packets/sec and the maximum transmission rate is 350 packets/sec. The corresponding traffic intensity is 500/350 =1.43 > 1. Loss will eventually occur for each ...
21. 删除视图:DROP VIEW 语句(Problem 21) DROP VIEW 语句用于删除一个视图。 22. 修改表结构:ALTER TABLE 语句(Problem 22) ALTER TABLE 语句用于修改表的结构,例如添加或删除列。 23. 全文本搜索:...
Title: Computer-Based Problem Solving Process Author: Teodor Rus Length: 350 pages ...Chapter 21. Efficiency of Batch Operating Systems Chapter 22. Convenience of the BOS Chapter 23. Real-Time Systems
基于TEAM (testing electromagnetic Problem 21 基准模型,从实验和仿真计算两方面系统地研究 多谐波激励下变压器结构件杂散损耗建模与验证方法。考虑 线圈涡流损耗的影响,提出一种基于实验更准确地确定结构 件杂散...
C#,21根火柴棍问题(21 Matchticks Problem)的算法与源代码 21根火柴棍问题是西方经典游戏之一。 给定21根火柴,2个人A和B(比如:分别是计算机和用户)。 每个人一次可以挑选 1-- 4 根火柴。 被迫挑最后一根...
例如,在对TEAM Problem 21 (Model B) 进行计算时,可以采用以下形式的双重傅立叶级数逼近: \[ B_z(x,y) = \sum_{m=1}^{\infty} \sum_{n=1}^{\infty} A_{mn} \cos(u_m \pi x / a) \cos(v_n \pi y / b) \] 其中,$...
21. 〔用 手 或 器 具 〕击 ; 打 - hit 22. 立即;马上 - immediately 23. 陷入;参与 - get involved 24. 绷带 - bandage 25. 生病的;有病的 - sick 26. 膝;膝盖 - knee 27. 鼻出血 - nosebleed 28. 呼吸 - ...
1 Introduction......Page 21 --- Problem Solving & Traditional AI Problems......Page 27 POLyA’s five sTePs fOr PrOBLem sOLvinG......Page 28 PrOBLem-sOLvinG Techniques......Page 33 humAn WinDOW.........
Title: Problem Solving in Data Structures & Algorithms Using Java: The Ultimate Guide to Programming Author: Hemant Jain Length: 436 pages Edition: First Edition Language: English Publisher: ...
ASP.NET Core Recipes A Problem-Solution Approach(2nd) 英文epub 第2版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
Designing an efficient algorithm to solve a computer science problem is a skill of Computer programmer. This is the skill which tech companies like Google, Amazon, Microsoft, Adobe and many others ...
"JEDEC JESD671D:2018 Device Quality Problem Analysis and Corrective Action Resolution Methodology" 本资源是JEDEC(Joint Electron Devices Engineering Council,电子器件工程理事会)发布的一份标准文档,...
### APIO2015 Problemset - Bali Sculptures #### 问题背景 在亚洲太平洋信息学奥林匹克(Asia-Pacific Informatics Olympiad,简称APIO)2015年的竞赛中,有一道名为“Bali Sculptures”的题目。这道题目的背景...
JEDEC JESD671D:2018 Device Quality Problem Analysis and Corrective Action Resolution Methodology - 完整英文电子版(21页).zip
为了验证所提出的方法,研究人员选择了Team Problem 21-A作为磁场测试模型,并对模型的测量损失与计算损失进行了对比分析。结果表明,计算出的磁通量密度Bx与实际测量值非常吻合。 此外,本文还提供了大型电力...
### 使用Python解决问题与数据结构(第3.0版) #### 一、引言 本章节首先介绍了本书的主要目的,即帮助读者理解计算机科学的基本概念、编程以及如何利用算法和数据结构来解决实际问题。该书适合初学者学习,并且...
C#,电话数字键盘问题(Mobile Numeric Keypad problem)的算法与源代码 电话数字键盘问题 提供移动数字键盘。您只能按向上、向左、向右或向下至当前按钮的按钮。不允许您按最下面一行的角点按钮(即.*和#)。 ...
21. APG40 related problem 28 21.1 These data must be provided for every trouble report. 28 21.2 STS related problem 28 21.3 Timezone problems 28 21.4 Audit Log problem 29 21.5 FMS related problem 29 ...