`
水木清华77
  • 浏览: 36247 次
  • 性别: 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

    0-1-knapsack-problem-master (23).zip

    【标题】:“0-1-knapsack-problem-master (23).zip”这个压缩包文件的标题暗示了其中包含的是关于0-1背包问题的解决代码或算法实现。0-1背包问题是一个经典的组合优化问题,常在计算机科学,尤其是运筹学和算法设计...

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

    0-1-knapsack-problem-master (23)c.zip

    0-1 背包问题(0-1 Knapsack Problem)是计算机科学中的一个经典优化问题,尤其在算法设计和组合优化领域占有重要地位。它源于实际生活中的物品打包问题,目标是在有限的容量限制下,选择价值最大的物品放入背包。在...

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

    C#,煎饼排序问题(Pancake Sorting Problem)算法与源代码

    C#,煎饼排序问题(Pancake Sorting Problem)算法与源代码 煎饼排序问题 给定一个未排序的数组,任务是对给定数组进行排序。您只能在阵列上执行以下操作。 翻转(arr,i):将数组从0反转为i 示例: 输入:arr[]={...

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

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

    C#,电话数字键盘问题(Mobile Numeric Keypad problem)的算法与源代码

    C#,电话数字键盘问题(Mobile Numeric Keypad problem)的算法与源代码 电话数字键盘问题 提供移动数字键盘。您只能按向上、向左、向右或向下至当前按钮的按钮。不允许您按最下面一行的角点按钮(即.*和#)。 ...

    爱立信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

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

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

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

    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