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 28. In fact, there are exactly four numbers below fifty that can be expressed
in such a way:
28 = 22 + 23 + 24
33 = 32 + 23 + 24
49 = 52 + 23 + 24
47 = 22 + 33 + 24
How many numbers below fifty million can be expressed as the sum of a prime square, prime cube, and prime fourth power?
先推断数的大致范围:sqrt(50000000)=7081
求出2~7081之间的全部质数
然后三层循环便利出全部能表示出的50000000以内的整数
#include <iostream>
#include <string>
#include <map>
using namespace std; bool isPrime[7081];
int prime[2000]; void judge()
{
for (int i = 2; i < 7081; i++)
{
if (isPrime[i])
{
for (int j = i; j*i < 7081; j++)
isPrime[j*i] = 0;
}
}
} int getPrime()
{
int count = 0;
for (int i = 2; i < 7081; i++)
{
if (isPrime[i])
{
prime[count++] = i;
}
}
return count;
} int main()
{
memset(isPrime, true, sizeof(isPrime));
judge();
int num = getPrime();
map<int, int>mp;
for (int i = 0; i < num; i++)
{
int a = prime[i] * prime[i] * prime[i] * prime[i];
if (a>50000000)
break;
for (int j = 0; j < num; j++)
{
int b = prime[j] * prime[j] * prime[j];
if (a + b>50000000)
break;
for (int k = 0; k < num; k++)
{
int c = prime[k] * prime[k];
if (a + b + c>50000000)
break;
mp[a + b + c]++;
}
}
} cout << mp.size() << endl;
system("pause");
return 0;
}
Project Euler:Problem 87 Prime power triples的更多相关文章
- Project Euler:Problem 77 Prime summations
It is possible to write ten as the sum of primes in exactly five different ways: 7 + 3 5 + 5 5 + 3 + ...
- Project Euler:Problem 41 Pandigital prime
We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly o ...
- Project Euler:Problem 55 Lychrel numbers
If we take 47, reverse and add, 47 + 74 = 121, which is palindromic. Not all numbers produce palindr ...
- Project Euler:Problem 63 Powerful digit counts
The 5-digit number, 16807=75, is also a fifth power. Similarly, the 9-digit number, 134217728=89, is ...
- Project Euler:Problem 47 Distinct primes factors
The first two consecutive numbers to have two distinct prime factors are: 14 = 2 × 7 15 = 3 × 5 The ...
- Project Euler:Problem 86 Cuboid route
A spider, S, sits in one corner of a cuboid room, measuring 6 by 5 by 3, and a fly, F, sits in the o ...
- 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 ...
- 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 ...
- Project Euler:Problem 37 Truncatable primes
The number 3797 has an interesting property. Being prime itself, it is possible to continuously remo ...
随机推荐
- 队列 LinkedBlockingQueue
1 api java.util.concurrent包下的新类.LinkedBlockingQueue就是其中之一,是一个阻塞的线程安全的队列,底层采用链表实现. Li ...
- 每天一个linux命令1之scp
不同的Linux之间copy文件常用有3种方法: 第一种就是ftp,也就是其中一台Linux安装ftpServer,这样可以另外一台使用ftp的client程序来进行文件的copy. 第二种方法就是采 ...
- Android UI 常用图标尺寸规范
1. 程序启动图标: LDPI (Low Density Screen,120 DPI),其图标大小为 36 x 36 px. MDPI (Medium Density Screen, 160 DPI ...
- ubuntu安装KVM
1. vmware安装ubuntu-14.04.1-server-amd64.iso.2. 安装完成后关机--右键虚拟机--setting--hardware--Processors--将 virtu ...
- JAVA中使用freemark生成自定义文件(json、excel、yaml、txt)
原文:http://blog.csdn.net/jinzhencs/article/details/51461776 场景:在我们工作中,有时需要生成一些文件,可能它不是一种标准的格式,比如JSON. ...
- 教育 z
奥巴马母亲留给儿子的遗产,不是谎言,而是让反对派不敢戮辨的——伟大的人格及优秀! 相比于奥巴马的母亲,中国式父母,更愿意走省心的路子.给孩子最催肥的食物,最昂贵的衣物,最庸懒的生活环境,不让孩子做任何 ...
- linux 通过两个网卡,连接不同的不同的网段
linux数据包转发功能 A:192.168.xxx.xxx B:172.24.xxx.xxx, 从而实现了A网段和B网段的互通. 原因Linux机器可以通过设置实现数据包的转发功能. #echo ...
- QT5.8+vs2015配置以及qt creater中出现中文乱码解决办法之一
1.参考此文档:QT5.6+vs2015配置: 2.出现乱码问题时候 在头文件上加入: #pragma execution_character_set("utf-8") //加入这 ...
- 利用chrony和ntp搭建时间同步服务器
利用chrony和ntp搭建时间同步服务器 环境说明 系统版本 CentOS 6.9 x86_64 Network Time Protocol(NTP,网络时间协议)用于同步它所有客户端时钟的服 ...
- 【转】Linux 中清空或删除大文件内容的五种方法(truncate 命令清空文件)
原文: http://www.jb51.net/article/100462.htm truncate -s 0 access.log -------------------------------- ...