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的更多相关文章

  1. 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 + ...

  2. 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 ...

  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 63 Powerful digit counts

    The 5-digit number, 16807=75, is also a fifth power. Similarly, the 9-digit number, 134217728=89, is ...

  5. 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 ...

  6. 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 ...

  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 89 Roman numerals

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

  9. Project Euler:Problem 37 Truncatable primes

    The number 3797 has an interesting property. Being prime itself, it is possible to continuously remo ...

随机推荐

  1. java的一些基本常识

    1.什么是java虚拟机?为什么把java称作是“无关平台的语言”? java虚拟机是一个可以执行Java字节码的虚拟进程.Java源文件被编译成能被Java虚拟机执行的字节码文件. Java 被设计 ...

  2. 常用SQL收藏

    原文:常用SQL收藏 MSSQL Split表字段 --拆分字符串之后匹配结果集合 CREATE FUNCTION [dbo].[fnSplit]( @sInputList VARCHAR(8000) ...

  3. android开发之自定义圆形ImagView

    在日常使用中我们经常会使用到圆形的图片,但是android系统中并没有默认的圆形控件,所以我们需要自己来写一个自定义的ImagView来显示一张圆形的图片,下面先看效果 详细的方法是我们自定义一个类, ...

  4. mac下npm/node的安装和卸载、升级;node、npm升级后最后删掉node_modules重新安装

    mac还是使用brew install简单一些:最好使用一种安装方式,不要多种方式互用: 更新npm到最新版本npm install -g npm更新npm到指定版本 npm -g install n ...

  5. OpenGL帧缓存对象(FBO:Frame Buffer Object) 【转】

    http://blog.csdn.net/dreamcs/article/details/7691690 原文地址http://www.songho.ca/opengl/gl_fbo.html 但有改 ...

  6. 删除windows服务命令

    打开命令框:输入sc delete 服务名 例如删除elasticsearch-service-x64服务 sc delete elasticsearch-service-x64

  7. linux中grep命令

    grep 是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来. grep常用用法 [root@www ~]# grep [-acinv] [--color=auto] '搜寻字 ...

  8. ssh免密码登录之分发密钥

    ssh免密码登录之分发密钥 1.ssh免密码登录 密码登录和密钥登录有什么不同? 密码登录(口令登录),每次登录都需要发送密码(ssh) 密钥登录,分为公钥和私钥,公钥相当于锁,私钥相当于钥匙 1.1 ...

  9. 转:提高ios通过率的注意点

    http://bugly.qq.com/bbs/forum.php?mod=viewthread&tid=431 Bugly 技术干货系列内容主要涉及移动开发方向,是由 Bugly 邀请腾讯内 ...

  10. [WCF菜鸟]什么是WCF

    一.概述 Windows Communication Foundation(WCF)是由微软发展的一组数据通信的应用程序开发接口,可以翻译为Windows通讯接口,它是.NET框架的一部分.由 .NE ...