A natural number, N, that can be written as the sum and product of a given set of at least two natural numbers, {a1a2, ... , ak}
is called a product-sum number: N = a1 + a2 + ... + ak = a1 × a2 × ... × ak.

For example, 6 = 1 + 2 + 3 = 1 × 2 × 3.

For a given set of size, k, we shall call the smallest N with this property a minimal product-sum number. The minimal product-sum numbers for sets of size, k =
2, 3, 4, 5, and 6 are as follows.

k=2: 4 = 2 × 2 = 2 + 2

k=3: 6 = 1 × 2 × 3 = 1 + 2 + 3

k=4: 8 = 1 × 1 × 2 × 4 = 1 + 1 + 2 + 4

k=5: 8 = 1 × 1 × 2 × 2 × 2 = 1 + 1 + 2 + 2 + 2

k=6: 12 = 1 × 1 × 1 × 1 × 2 × 6 = 1 + 1 + 1 + 1 + 2 + 6

Hence for 2≤k≤6, the sum of all the minimal product-sum numbers is 4+6+8+12 = 30; note that 8 is only counted once in the sum.

In fact, as the complete set of minimal product-sum numbers for 2≤k≤12 is {4, 6, 8, 12, 15, 16}, the sum is 61.

What is the sum of all the minimal product-sum numbers for 2≤k≤12000?

n[k]表示minimal product-sum numbers for size=k

n[k]的上界为2*k,由于2*k总是能分解成2*k,然后2*k=k+2+(1)*(k-2)

显然n[k]的下界为k

对于一个数num   因式分解后因子个数为product   这些因子的和为sump

则须要加入的1的个数为num-sump,所以size k=num-sump+product

maxk = 12000
n=[2*maxk for i in range(maxk)] def getpsn(num,sump,product,start):
#print(num,' ',sump,' ',product)
k = num - sump + product
if k < maxk:
if num < n[k]:
n[k] = num
for i in range(start,maxk//num * 2): #控制num<=2*maxk
getpsn(num * i,sump + i,product + 1,i) getpsn(1,1,1,2)
ans=sum(set(n[2:]))
print(ans)

Project Euler:Problem 88 Product-sum numbers的更多相关文章

  1. Project Euler:Problem 61 Cyclical figurate numbers

    Triangle, square, pentagonal, hexagonal, heptagonal, and octagonal numbers are all figurate (polygon ...

  2. Project Euler:Problem 42 Coded triangle numbers

    The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangl ...

  3. Project Euler:Problem 55 Lychrel numbers

    If we take 47, reverse and add, 47 + 74 = 121, which is palindromic. Not all numbers produce palindr ...

  4. Project Euler:Problem 87 Prime power triples

    The smallest number expressible as the sum of a prime square, prime cube, and prime fourth power is ...

  5. Project Euler:Problem 28 Number spiral diagonals

    Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is forme ...

  6. Project Euler:Problem 32 Pandigital products

    We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly o ...

  7. Project Euler:Problem 76 Counting summations

    It is possible to write five as a sum in exactly six different ways: 4 + 1 3 + 2 3 + 1 + 1 2 + 2 + 1 ...

  8. Project Euler:Problem 34 Digit factorials

    145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145. Find the sum of all numbers which are ...

  9. Project Euler:Problem 89 Roman numerals

    For a number written in Roman numerals to be considered valid there are basic rules which must be fo ...

随机推荐

  1. 安装MySQL最后一步出现错误Error Nr.1045解决方法

    转自:https://blog.csdn.net/gsls200808/article/details/46846019 安装MySQL最后一步出现错误Error Nr.1045 Connection ...

  2. 利用阿里云加速Docker For Windows

    1.进入阿里云的容器镜像服务,找到镜像中心的镜像加速器. https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors 2.进入Docker ...

  3. 一个 passive 引发的bug

    不是什么很难的东西,权且做个记录. 首先说下背景,目前的项目中,需要同时绑定 wheel 和 scroll 事件. 绑定 wheel,目的是开发 ctrl + wheel 缩放页面功能,此功能与浏览器 ...

  4. Codeforces Round #198 (Div. 2)A,B题解

    Codeforces Round #198 (Div. 2) 昨天看到奋斗群的群赛,好奇的去做了一下, 大概花了3个小时Ak,我大概可以退役了吧 那下面来稍微总结一下 A. The Wall Iahu ...

  5. 9.14[XJOI] NOIP训练33

    今日9.14 洛谷打卡:大凶!!!(换个字体玩玩qwq) -------------------------------------------------------- 一个超颓的上午 今天又是fl ...

  6. Unity3d transform

    using UnityEngine; using System.Collections; public class transform : MonoBehaviour { // Use this fo ...

  7. 关于CI中的MVC以及扩展CI中的控制器

    MVC是一种设计模式模式,M(模型)—V(视图)—C(控制器): MVC的核心思想是强制开发者在进行项目开发时,将数据的输入,处理,输出分开编写: 1.入口文件:该文件是唯一一个给浏览器直接请求的脚本 ...

  8. Vim常用又容易忘的命令

    一篇讲的不错的教程 :noh 取消搜索高亮 x 删当前光标所在的一个字符. :wq 存盘 + 退出 dd 删除当前行,并把删除的行存到剪贴板里 p 粘贴剪贴板 a → 在光标后插入 /pattern ...

  9. Linux date命令的用法(转)

    1.命令:date 2.命令功能:date 可以用来显示或设定系统的日期与时间. 3.命令参数 -d<字符串>:显示字符串所指的日期与时间.字符串前后必须加上双引号: -s<字符串& ...

  10. TensorFlow实战学习笔记(14)------VGGNet

    一.VGGNet:5段卷积[每段有2~3个卷积层+最大池化层][每段过滤器个数:64-128-256-512-512] 每段的2~3个卷积层串联在一起的作用: 2个3×3的卷积层串联的效果相当于一个5 ...