问题描述:
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
【标题】:“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...