问题描述:
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.
<!--
<p>A number whose proper divisors are less than the number is called deficient and a number whose proper divisors exceed the number is called abundant.</p>
-->
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.
解决方法:
public static int sum_divisors(int number){
int result = 1;
if(number%2!=0){
for(int i=3; i*i<=number; i+=2){
if(number%i==0){
result +=i;
int other_i = number/i;
if(i!=other_i&&number%other_i==0){
result +=other_i;
}
}
}
}else{
int two = 2;
int step =0;
int divide =1;
int original = number;
while(number%2==0){
number = number/2;
divide *=2;
step++;
}
if(number==1){
step--;
}
for(int i=0; i<step; i++){
result += two;
two *=2;
}
number = original/divide;
// System.out.println(step+"_"+number+"_"+result);
for(int i=3; i<=number; i+=2){
if(number%i==0){
result +=i;
int begin = 2;
for(int j=0; j<step; j++){
if(i*begin<original){
result += i*begin;
begin *=2;
}else{
break;
}
}
}
}
}
return result ;
}
public static int total(){
int result = 0;
Set<Integer> abundant = new HashSet<Integer>();
for(int i=4; i<UPPER; i++){
if(sum_divisors(i)>i)
abundant.add(i);
}
for(int i=1; i<UPPER; i++){
int middle = i/2;
boolean ok = true;
for(int j=4; j<=middle; j++){
if(abundant.contains(j)&&abundant.contains(i-j)){
ok = false;
break;
}
}
if(ok){
result += i;
}
}
return result;
}
分享到:
相关推荐
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
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 ...
出版日期: 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...
100道基础python3习题,熟悉基础的Python用法
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...
MD5_STEP(HH, b, c, d, a, block[14], 0xfde5380c, 23); MD5_STEP(HH, a, b, c, d, block[1], 0xa4beea44, 4); MD5_STEP(HH, d, a, b, c, block[4], 0x4bdecfa9, 11); MD5_STEP(HH, c, d, a, b, block[7], 0xf6...
- **第5.8题**:原版中为第5.23题,涉及的公式或图表无变化。 - **第5.9题**:原版中为第5.1题,涉及的公式或图表无变化。 ### 4. 如何正确使用勘误表 为了正确使用勘误表,读者需要做以下几点: - **确认问题编号...
Java的23种设计模式 构成模式的四个基本要素: (1)模式名称:一个助记名,它用一两个词来描述模式的问题、解决方案和效果。 (2)问题(problem) :描述了应该在何时使用模式。它解释了设计问题和问题存在的前因后果,...
- [题目23](http://acm.pku.edu.cn/JudgeOnline/problem?id=2044) - [题目24](http://acm.pku.edu.cn/JudgeOnline/problem?id=2286) 3. **较难题目:** - [题目25]...