`
水木清华77
  • 浏览: 37552 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Problem23

阅读更多
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;
    }
}
分享到:
评论

相关推荐

    计算机网络第六版答案

    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 ...

    MySQL数据库考试试题.docx

    23. 全文本搜索:MATCH() 函数(Problem 23) MATCH() 函数用于指定被搜索的列,在全文本搜索中使用。 24. 错误语句:不能使用运算符号(Problem 24) 在 SELECT 语句中,不能使用运算符号,例如 SELECT sal+1 ...

    Computer-Based.Problem.Solving.Process

    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++代码

    ### Knight Problem 使用 C++ 和 A* 算法解析 #### 一、Knight Problem 介绍 Knight Problem(骑士问题)通常是指在一个国际象棋棋盘上寻找一条路径,使得一个骑士能够从起始位置到达目标位置。由于骑士的移动方式...

    Problem Solving in Data Structures & Algorithms Using Java

    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.rar

    由于提供的信息较为有限,我们只能从文件名“Problem_E_of_the_2023_Huawei_Cup_Graduate_Mathemat_23yansaiE.rar”中提取出一些关键信息。首先,文件名提示这是一个与华为杯数学竞赛相关的文件,华为杯数学竞赛是由...

    Problem.Solving.in.Data.Structures.and.Algorithms.Using.Cplusplus.epub

    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 ...

    The Problem With Software: Why Smart Engineers Write Bad Code

    出版日期: 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...

    单峰测试函数:Axis、Quadric、Rosenbrock、SchwefelProblem12、SchwefelProblem22、SumSquar、Step

    类似于Schwefel's Problem 12,Schwefel's Problem 22也是Schwefel函数系列的一部分,用于评估优化算法在处理复杂多峰函数时的表现。它的最小值可能分布在不同的区域,挑战算法的全局探索能力。 6. **SumSquar(和...

    Python100经典练习题.zip_23R4_problemx4v_python3习题下载_python习题_python联系

    100道基础python3习题,熟悉基础的Python用法

    爱立信CSR数据采集规范

    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

    delphi2010皮肤控件-VCLSkinv5.30FS

    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_programmer_must_know_the_problem.rar_The Word_笔试”指的是一个针对编程人员的资源压缩包,其中包含25个关键问题,这些问题对于程序员在面试和笔试中都具有很高的参考价值。"The Word"可能是指文档...

    图灵机与计算问题 tuning machine and computation problem

    - **希尔伯特的23个问题**:1900年,数学家大卫·希尔伯特提出了一系列数学问题,其中第10个问题涉及是否存在一种有限的、机械的步骤来判断“丢番图方程”是否存在整数解。这个问题实际上是算法概念的早期雏形。 - *...

    MIT人工智能课程6.034课件

    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...

    Razavi, Behzad - Design of Analog CMOS Integrated Circuits (solution book + errata in problem sets)_p329.pdf

    - **第5.8题**:原版中为第5.23题,涉及的公式或图表无变化。 - **第5.9题**:原版中为第5.1题,涉及的公式或图表无变化。 ### 4. 如何正确使用勘误表 为了正确使用勘误表,读者需要做以下几点: - **确认问题编号...

    经典Java23种设计模式.rar

    Java的23种设计模式 构成模式的四个基本要素: (1)模式名称:一个助记名,它用一两个词来描述模式的问题、解决方案和效果。 (2)问题(problem) :描述了应该在何时使用模式。它解释了设计问题和问题存在的前因后果,...

    ACM学习资料汇总,ACMer要试试哦!

    - [题目23](http://acm.pku.edu.cn/JudgeOnline/problem?id=2044) - [题目24](http://acm.pku.edu.cn/JudgeOnline/problem?id=2286) 3. **较难题目:** - [题目25]...

    ansys license

    - **最大可用数量**:23,105个许可证。 - **版本号**:`2012.10`。 - **有效期**:2012年10月20日至2022年12月31日。 - **客户编号**:`00163423`。 - **发行者**:`LND`(推测为ANSYS License Network Daemon)。 -...

Global site tag (gtag.js) - Google Analytics