- 浏览: 36790 次
- 性别:
- 来自: 杭州
最新评论
A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number. A number n is called deficient if the sum of its proper divisors is less than n and it is called abundant if this sum exceeds n. As 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16, the smallest number that can be written as the sum of two abundant numbers is 24. By mathematical analysis, it can be shown that all integers greater than 28123 can be written as the sum of two abundant numbers. However, this upper limit cannot be reduced any further by analysis even though it is known that the greatest number that cannot be expressed as the sum of two abundant numbers is less than this limit. Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers.
package com.yao; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; /** * Created by IntelliJ IDEA. * User: Administrator * Date: 12-3-18 * Time: 下午12:50 */ public class Problem23 { public static void main(String[] args) { List<Integer> list=new ArrayList<Integer>(); for(int i=1;i<=28123;i++){ if(sum(i)>i) { list.add(i); } } Set<Integer> abundant2sum =new HashSet<Integer>(); int size=list.size(); int sum=0; for(int i=1;i<=28123;i++){ sum+=i; } for(int i=0;i<size;i++) for(int j=i;j<size;j++){ int k=list.get(i)+list.get(j); if(k<=28123){ if(!abundant2sum.contains(k)){ abundant2sum.add(k); sum-=k; } } } System.out.println(sum); } 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 862A unit fraction contains 1 in t ... -
Problem25
2012-04-26 16:33 882package com.yao.Algorithms; ... -
Problem24
2012-04-26 14:12 779package com.yao.Algorithms; ... -
Problem22
2012-03-17 23:13 767Using names.txt (right click an ... -
Problem21
2012-03-11 20:44 1202Problem 21 05 July 2002 Let ... -
Problem20
2011-12-15 14:09 800package com.yao.shuimu.euler; ... -
Problem19
2011-12-09 14:07 717package com.shui.mu.yao.io.algo ... -
Problem18/Problem67
2011-12-04 20:20 891package com.yao.Algorithms; ... -
Problem16
2011-12-02 15:32 415package com.shui.mu.yao.io.algo ... -
Problem15
2011-11-29 23:28 528package com.yao.Algorithms; ... -
Problem14
2011-11-29 11:37 704package com.shui.mu.yao.io.algo ... -
Problem13_1
2011-11-21 14:07 587package yao.taobao.jj; publi ... -
Problem13
2011-11-19 23:51 564package com.yao.Algorithms; ... -
Problem12
2011-11-07 20:04 708package com.shui.mu.yao.io.algo ... -
Problem11
2011-11-06 19:38 1191package com.yao.Algorithms; ... -
Problem10
2011-11-03 20:14 410package com.shui.mu.yao.io.algo ... -
Problem9
2011-11-03 16:04 745package com.shui.mu.yao.io.algo ... -
Problem8
2011-11-03 12:38 590package com.shui.mu.yao.io.algo ... -
Problem7
2011-11-03 11:25 450package com.shui.mu.yao.io.algo ...
相关推荐
23. The five layers in the Internet protocol stack are – from top to bottom – the application layer, the transport layer, the network layer, the link layer, and the physical layer. The principal ...
23. 全文本搜索:MATCH() 函数(Problem 23) MATCH() 函数用于指定被搜索的列,在全文本搜索中使用。 24. 错误语句:不能使用运算符号(Problem 24) 在 SELECT 语句中,不能使用运算符号,例如 SELECT sal+1 ...
Title: Computer-Based Problem Solving Process Author: Teodor Rus Length: 350 pages Edition: 1 Language: English Publisher: World Scientific Publishing Company ...Chapter 23. Real-Time Systems
### Knight Problem 使用 C++ 和 A* 算法解析 #### 一、Knight Problem 介绍 Knight Problem(骑士问题)通常是指在一个国际象棋棋盘上寻找一条路径,使得一个骑士能够从起始位置到达目标位置。由于骑士的移动方式...
Title: Problem Solving in Data Structures & Algorithms Using Java: The Ultimate Guide to Programming Author: Hemant Jain Length: 436 pages Edition: First Edition ...CHAPTER 23: SYSTEM DESIGN
Problem_E_of_the_2023_Huawei_Cup_Graduate_Mathemat_23yansaiE
【标题】:“0-1-knapsack-problem-master (23).zip”这个压缩包文件的标题暗示了其中包含的是关于0-1背包问题的解决代码或算法实现。0-1背包问题是一个经典的组合优化问题,常在计算机科学,尤其是运筹学和算法设计...
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 ...
0-1 背包问题(0-1 Knapsack Problem)是计算机科学中的一个经典优化问题,尤其在算法设计和组合优化领域占有重要地位。它源于实际生活中的物品打包问题,目标是在有限的容量限制下,选择价值最大的物品放入背包。在...
出版日期: 2018-10-23 pages 页数: (362) An industry insider explains why there is so much bad software―and why academia doesn’t teach programmers what industry wants them to know. Why is software so...
C#,煎饼排序问题(Pancake Sorting Problem)算法与源代码 煎饼排序问题 给定一个未排序的数组,任务是对给定数组进行排序。您只能在阵列上执行以下操作。 翻转(arr,i):将数组从0反转为i 示例: 输入:arr[]={...
100道基础python3习题,熟悉基础的Python用法
C#,电话数字键盘问题(Mobile Numeric Keypad problem)的算法与源代码 电话数字键盘问题 提供移动数字键盘。您只能按向上、向左、向右或向下至当前按钮的按钮。不允许您按最下面一行的角点按钮(即.*和#)。 ...
23. MGW related problem 37 23.1 Collect Configuration Data (CV) 37 23.2 Collect Alarm, Event, Availability and System Logs 37 23.3 C Collect Trace & Error logs, Processor loads and Disk space 37
类似于Schwefel's Problem 12,Schwefel's Problem 22也是Schwefel函数系列的一部分,用于评估优化算法在处理复杂多峰函数时的表现。它的最小值可能分布在不同的区域,挑战算法的全局探索能力。 6. **SumSquar(和...
News In 4.98 04/23/2008 *fix bug in Tbutton. News In 4.97 04/20/2008 *fix bug in Tlistview. News In 4.96 03/25/2008 *fix bug in Tlistview. News In 4.95 03/13/2008 *fix bug in dll forms. News In ...
标题中的“25_programmer_must_know_the_problem.rar_The Word_笔试”指的是一个针对编程人员的资源压缩包,其中包含25个关键问题,这些问题对于程序员在面试和笔试中都具有很高的参考价值。"The Word"可能是指文档...
- **希尔伯特的23个问题**:1900年,数学家大卫·希尔伯特提出了一系列数学问题,其中第10个问题涉及是否存在一种有限的、机械的步骤来判断“丢番图方程”是否存在整数解。这个问题实际上是算法概念的早期雏形。 - *...
23 Model merging, cross-modal coupling, course summary PROBLEM SETS TOPICS CODE FILES Problem Set 0 (PDF) Python programming, symbolic algebra Code for Problem Set 0 (ZIP) (This ZIP file contains: 5...