primes - Product of three primes divisible by sum of those primes
问题描述
I found this problem in a cp contest which is over now so it can be answered. Three primes (p1,p2,p3) (not necessarily distinct) are called special if (p1+p2+p3) divides p1*p2*p3. We have to find the number of these special pairs if the primes can't exceed 10^6
I tried brute force method but it timed out. Can there be any other method?
解决方案
如果您超时,那么您需要进行一些智能搜索以替换蛮力。一百万以下的质数只有不到 80,000 个,所以你超时也就不足为奇了。
所以,你需要开始更仔细地寻找。
例如,p+2 也是素数的任何三元组 (2, p, p+2) 都将满足标准:
- 2 + 3 + 5 = 10;2 * 3 * 5 = 30;30 / 10 = 3。
- 2 + 5 + 7 = 14;2 * 5 * 7 = 70。70 / 14 = 5。
- ...
- 2 + p + p+2 = 2(p+2); 2 * p * (p+2) = 2p(p+2); 2p(p+2) / 2(p+2) = p。
- ...
还有其他以 2 开头的三元组吗?有以 3 开头的三元组吗?如果 p1=3,p2 和 p3 取什么形式?运行你的程序,最多 500 个左右,并在结果中寻找模式。然后将这些结果外推到 10^6。
我假设您正在使用 Sieve 生成初始素数列表。
推荐阅读
- dependencies - 将 Python3 环境迁移到虚拟 - 管理导入依赖项
- javascript - 需要使用以下代码进行说明
- android - 无法安装应用程序:INSTALL_FAILED_VERSION_DOWNGRADE
- javascript - 在 Vue JS 中创建卡片滑块
- reactjs - 使用 Spring Boot 和 ReactJS 的 IDP 发起的 SSO
- docker - 访问在 Linux 主机上的 docker 容器中运行的 PROPER IP 上的服务
- php - 如何将 PHP cURL 数据转换为数组?
- angular - 错误类型错误:无法读取未定义的属性“帖子”
- php - 在 PHP 调度系统槽中添加范围
- python - 如何使用嵌套字典遍历 url?