转帖:Euler's Sum of Powers Conjecture

存不存在四个大于1的整数的五次幂恰好是另一个整数的五次幂?

暴搜:O(n^4)

用dictionary:O(n^3)

 import itertools

 def euler(m):
"""Yield tuples (a, b, c, d, e) such that a^5 + b^5 + c^5 + d^5 = e^5,
where all are integers, and 1 < a ≤ b ≤ c ≤ d < e < m."""
powers = [e**5 for e in range(2, m)]
pairs = {sum(pair): pair
for pair in itertools.combinations_with_replacement(powers, 2)}
for pair1 in pairs:
for e5 in powers:
pair2 = e5 - pair1
if pair2 in pairs:
yield fifthroots(pairs[pair1] + pairs[pair2] + (e5,)) def fifthroots(nums):
"Sorted integer fifth roots of a collection of numbers."
return tuple(sorted(int(round(x ** (1/5))) for x in nums))

Euler's Sum of Powers Conjecture的更多相关文章

  1. [CSAcademy]Sum of Powers

    [CSAcademy]Sum of Powers 题目大意: 给定\(n,m,k(n,m,k\le4096)\).一个无序可重集\(A\)为合法的,当且仅当\(|A|=m\)且\(\sum A_i=n ...

  2. [伯努利数] poj 1707 Sum of powers

    题目链接: http://poj.org/problem?id=1707 Language: Default Sum of powers Time Limit: 1000MS   Memory Lim ...

  3. 【POJ1707】【伯努利数】Sum of powers

    Description A young schoolboy would like to calculate the sum for some fixed natural k and different ...

  4. Project Euler 30 Digit fifth powers

    题意:判断一个数 N 的每一位的5次方的和是否为其本身 ,求出所有满足条件的数的和 思路:首先设这个数 N 为 n 位,可以简单的判断一下这个问题的上界 10 ^ n <= 9 ^ 5 × n, ...

  5. UVA766 Sum of powers(1到n的自然数幂和 伯努利数)

    自然数幂和: (1) 伯努利数的递推式: B0 = 1 (要满足(1)式,求出Bn后将B1改为1 /2) 参考:https://en.wikipedia.org/wiki/Bernoulli_numb ...

  6. POJ 1707 Sum of powers(伯努利数)

    题目链接:http://poj.org/problem?id=1707 题意:给出n 在M为正整数且尽量小的前提下,使得n的系数均为整数. 思路: i64 Gcd(i64 x,i64 y) { if( ...

  7. sum of powers

    题意: 考虑所有的可重集{a1,a2,a3....ak} 满足a1+a2+....+ak=n,求所有a1^m+a2^m+a3^m的和 n,m,k<=5000 题解: part1: 考虑f[i][ ...

  8. UVa 766 Sum of powers (伯努利数)

    题意: 求 ,要求M尽量小. 析:这其实就是一个伯努利数,伯努利数公式如下: 伯努利数满足条件B0 = 1,并且 也有 几乎就是本题,然后只要把 n 换成 n-1,然后后面就一样了,然后最后再加上一个 ...

  9. Project Euler 46 Goldbach's other conjecture( 线性筛法 )

    题意: 克里斯蒂安·哥德巴赫曾经猜想,每个奇合数可以写成一个素数和一个平方的两倍之和 9 = 7 + 2×1215 = 7 + 2×2221 = 3 + 2×3225 = 7 + 2×3227 = 1 ...

随机推荐

  1. charles 偏好设置

    本文参考:charles 偏好设置 charles 偏好设置  偏好设置,注意作用如下 用户界面 视图 启动设置 警告设置 视图选项 头和主体一起查看 请求和响应页查看 结构试图布局 序列试图布局 显 ...

  2. (CVE-2017-7494)Samba远程代码执行[Linux]

    简介 此漏洞是针对开启了共享的smb服务 漏洞利用 启动msfconsole search is_known_pipename   搜索此模块 use exploit/linux/samba/is_k ...

  3. 【转】JS大总结(带实例)

    JS大总结(带实例) JavaScript事务查询综合click() 对象.click() 使对象被点击.closed 对象.closed 对象窗口是否已封闭true/falseclearTimeou ...

  4. Machine Learning Stanford Univerisity (Week 1)

    1. 机器学习是什么? "A computer program is said to learn from experience E with respect to some class o ...

  5. K8S从入门到放弃系列-(2)集群根证书准备

    k8s从1.8版本开始,集群中各个组件需要使用TLS证书对通信进行加密,每个k8s集群都需要有独立的CA证书体系,这里我们采用比较常用的CloudFlare 的 PKI 工具集 cfssl 来生成 C ...

  6. Sql Server\ MySql 日期

    ------------------MS Sql Server------------------ declare @ctrBeginTime =null; if(@ctrBeginTime Is N ...

  7. Django中常用的那些模块路径

    Django中常用的那些模块路径 from django.shortcuts import HttpResponse, render, redirect from django import temp ...

  8. Redis主从及Cluster区别及注意事项

    https://yq.aliyun.com/articles/647342 https://blog.csdn.net/biren_wang/article/details/78117392 http ...

  9. 怎样理解script标签的defer属性和async属性

    如果script标签是引用的外部js文件, 那就会有一个下载js文件这一过程, 为了不因为这个下载过程而阻塞页面解析与渲染, 我们需要一种机制来解决这一问题, 方法之一就是使用 defer和async ...

  10. (四)Decorator设计模式解决GET/POST请求的乱码问题(转)

    一.Decorator设计模式 1.1.Decorator设计模式介绍 当某个对象的方法不适应业务需求时,通常有2种方式可以对方法进行增强: 编写子类,覆盖需增强的方法. 使用Decorator设计模 ...