鱼C论坛

 找回密码
 立即注册
查看: 2096|回复: 2

题目131:求使得n^3 + n^2 * p为完全立方数的质数p

[复制链接]
发表于 2016-8-23 17:21:24 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 永恒的蓝色梦想 于 2020-6-3 19:09 编辑
Prime cube partnership

There are some prime values, p, for which there exists a positive integer, n, such that the expression n3 + n2p is a perfect cube.

For example, when p = 19, 83 + 82×19 = 123.

What is perhaps most surprising is that for each prime with this property the value of n is unique, and there are only four such primes below one-hundred.

How many primes below one million have this remarkable property?


题目:

对于某些质数 p,存在一个正整数 n,使得 n3 + n2p 是完全立方数。

例如,当 p=19 时,83 + 82×19 = 123.

令人惊奇的是,对于每个具有上述性质的质数 p,对应的 n 是唯一的,而且 100 以下只有 4 个这样的质数。

一百万以下有多少质数具有上述性质?

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-11-21 04:27:23 | 显示全部楼层
先暂时这样,等前面100多题都做了再回来弄质数列表优化代码


  1. xor esi,esi
  2. xor eax,eax
  3. inc eax
  4. xor ebx,ebx
  5. xor ecx,ecx
  6. add cl,3

  7. _i:
  8. add bx,6
  9. add eax,ebx
  10. cmp eax,1000000
  11. jnc _ok
  12. push cx
  13. push eax
  14. _d:
  15. xor edx,edx
  16. div ecx
  17. cmp eax,ecx
  18. jc _a
  19. add cx,2
  20. mov eax,[esp]
  21. test edx,edx
  22. jnz _d
  23. jmp _n
  24. _a:
  25. inc esi
  26. _n:
  27. pop eax
  28. pop cx
  29. jmp _i

  30. _ok:
复制代码


所用时间: 0.00063秒
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-7-19 14:01:14 | 显示全部楼层
  1. """
  2. n^3+n^2*p=k^3 (p is prime, n and k are int)
  3. n^3*(p/n+1)=k^3
  4. n*((p+n)/n)^(1/3)=k
  5. so, p+n and n need to be perfect cubes
  6. let n = x^3 and p+n = y^3, then p=y^3-x^3=(y-x)*(y^2+x*y+x^2)
  7. due to p is prime, so y-x must be 1, so p=(x+1)^3-x^3 and p must be prime and p < 1000000.
  8. so, let's check x and y...
  9. """
  10. primes=[True]*1000000
  11. primes[:2]=[False]*2
  12. for i,prime in enumerate(primes):
  13.         if prime:
  14.                 for j in range(i*i, 1000000, i):
  15.                         primes[j]=False
  16. count = 0
  17. for x in range(1, 1000):
  18.         p = (x+1)**3-x**3
  19.         if p >= 1000000:
  20.                 break
  21.         if primes[p]:
  22.                 count += 1
  23. print(count)
复制代码

173
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-20 01:44

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表