题意:

完全数是指真因数之和等于自身的那些数。例如,28的真因数之和为1 + 2 + 4 + 7 + 14 = 28,因此28是一个完全数。

一个数n被称为亏数,如果它的真因数之和小于n;反之则被称为盈数。

由于12是最小的盈数,它的真因数之和为1 + 2 + 3 + 4 + 6 = 16,所以最小的能够表示成两个盈数之和的数是24。通过数学分析可以得出,所有大于28123的数都可以被写成两个盈数的和;尽管我们知道最大的不能被写成两个盈数的和的数要小于这个值,但这是通过分析所能得到的最好上界。

找出所有不能被写成两个盈数之和的正整数,并求它们的和。

思路:此题与欧拉21题相似


/*************************************************************************
> File Name: euler023.c
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年06月30日 星期五 19时30分05秒
************************************************************************/ #include <stdio.h>
#include <inttypes.h> #define MAX_N 28123 int32_t isPrime[MAX_N + 10] = {0}; // 记录最小素数幂次方isPrime[24] = 8 (2^3)
int32_t prime[MAX_N + 10] = {0}; // 记录素数
int32_t d[MAX_N + 10] = {0}; // 记录整数分解约数和
int32_t abundantSum[MAX_N + 10] = {0};
int32_t vis[MAX_N + 10] = {0}; void Init() {
for (int32_t i = 2 ; i <= MAX_N ; i++) {
if (!isPrime[i]) {
isPrime[i] = i;
prime[++prime[0]] = i;
d[i] = i + 1;
}
for (int32_t j = 1 ; j <= prime[0] ; j++) {
if (i * prime[j] > MAX_N) break;
if (i % prime[j] != 0) { // 在prime[j]还小于i的最小素因子时
isPrime[i * prime[j]] = prime[j];
d[i * prime[j]] = d[i] * d[prime[j]];
} else {
isPrime[i * prime[j]] = isPrime[i] * prime[j];
d[i * prime[j]] = d[i] * (isPrime[i] * prime[j] * prime[j] - 1) / (isPrime[i] * prime[j] - 1);
break;
}
}
}
for (int32_t i = 1 ; i <= MAX_N ; i++) {
d[i] -= i;
if (d[i] <= i) continue;
abundantSum[++abundantSum[0]] = i;
}
for (int32_t i = 1 ; i < abundantSum[0] ; i++) {
for (int32_t j = i + 1 ; j <= abundantSum[0] ; j++) {
if (abundantSum[i] + abundantSum[j] > MAX_N) continue;
vis[abundantSum[i] + abundantSum[j]] = 1;
}
}
}
int32_t main() {
Init();
int32_t sum = 0;
for (int32_t i = 1 ; i <= MAX_N ; i++) {
if (vis[i]) continue;
sum += i;
}
printf("%d\n",sum);
return 0;
}

Project Euler 23 Non-abundant sums( 整数因子和 )的更多相关文章

  1. Project Euler P105:Special subset sums: testing 特殊的子集和 检验

    Special subset sums: testing Let S(A) represent the sum of elements in set A of size n. We shall cal ...

  2. Python练习题 040:Project Euler 012:有超过500个因子的三角形数

    本题来自 Project Euler 第12题:https://projecteuler.net/problem=12 # Project Euler: Problem 12: Highly divi ...

  3. [project euler] program 4

    上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...

  4. Python练习题 029:Project Euler 001:3和5的倍数

    开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...

  5. Project Euler 第一题效率分析

    Project Euler: 欧拉计划是一系列挑战数学或者计算机编程问题,解决这些问题需要的不仅仅是数学功底. 启动这一项目的目的在于,为乐于探索的人提供一个钻研其他领域并且学习新知识的平台,将这一平 ...

  6. Python练习题 045:Project Euler 017:数字英文表达的字符数累加

    本题来自 Project Euler 第17题:https://projecteuler.net/problem=17 ''' Project Euler 17: Number letter coun ...

  7. Python练习题 039:Project Euler 011:网格中4个数字的最大乘积

    本题来自 Project Euler 第11题:https://projecteuler.net/problem=11 # Project Euler: Problem 10: Largest pro ...

  8. Project Euler 9

    题意:三个正整数a + b + c = 1000,a*a + b*b = c*c.求a*b*c. 解法:可以暴力枚举,但是也有数学方法. 首先,a,b,c中肯定有至少一个为偶数,否则和不可能为以上两个 ...

  9. Project Euler 44: Find the smallest pair of pentagonal numbers whose sum and difference is pentagonal.

    In Problem 42 we dealt with triangular problems, in Problem 44 of Project Euler we deal with pentago ...

随机推荐

  1. mongodb--入门知识点

    命令 mongo.exe,命令行客户端Shell工具. mongod.exe,数据库服务程序. mongodump.exe,数据库备份程序. mongoexport.exe,数据导出工具. mongo ...

  2. Spring @async 方法上添加该注解实现异步调用的原理

    Spring @async 方法上添加该注解实现异步调用的原理 学习了:https://www.cnblogs.com/shangxiaofei/p/6211367.html 使用异步方法进行方法调用 ...

  3. pl/sql developer br 文件

    pl/sql developer br 文件 Version=1 RightMargin=72 Indent=2 UseTabCharacter=FALSE TabCharacterSize=2 Al ...

  4. sql系列(基础篇)-前言 课前补充知识

    前言 课前补充知识 Number(p,s) Number(p,s):数字类型,p 表示数字的有效长度(从数字的左边第 1 位不为 0 的開始算起,直到最右边的长度.取值范围 0~38 位),s 表示数 ...

  5. 《转》Ceilometer Alarm API 參数具体解释 及 举例说明

    Ceilometer Alarm是H版新加入的功能,监控报警是云平台必不可少的部分,Ceilometer已经实现了比較完好的监控体系.报警怎么能缺少呢?用过AWS CloudWatch Alarm的人 ...

  6. php建立简单的用户留言系统

    php建立简单的用户留言系统 样例 addMsg.php--添加留言页面 doAction.php--响应添加留言页面 . viewMsg.php--显示留言页面 目录结构 addMsg.php--添 ...

  7. CodeForces 660A

    Description You are given an array of n elements, you must make it a co-prime array in as few moves ...

  8. ServletContextAware、ServletRequestAware、ServletResponseAware、SessionAware

    转自:ServletContextAware.ServletRequestAware.ServletResponseAware.SessionAware Struts 2提供了Aware接口.Awar ...

  9. day63-webservice 08.在web项目中配置带有接口的webservice服务

    这个是配置带有接口的WebService的服务. http://localhost:8080/cxf-web-server/service 带有接口的实现类也给它做好了.jaxws:endpoint是 ...

  10. [JavaEE] DWR框架实现Ajax

    Ajax是时下比较流行的一种web界面设计新思路,其核心思想是从浏览器获取XMLHttp对象与服务器端进行交互. DWR(Direct Web Remoting)就是实现了这种Ajax技术的一种web ...