Project Euler:Problem 39 Integer right triangles
If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.
{20,48,52}, {24,45,51}, {30,40,50}
For which value of p ≤ 1000, is the number of solutions maximised?
#include <iostream>
using namespace std; int main()
{
int ans = 0;
int maxp = 0;
for (int i = 12; i <= 1000; i++)
{
int maxc = 0;
for (int a = 1; a < i; a++)
{
for (int b = 1; b < a; b++)
{
int c = i - a - b;
if (c < 0)
break;
if (a*a + b*b == c*c)
maxc++;
}
}
if (maxc>ans)
{
ans = maxc;
maxp = i;
} }
cout << ans << " " << maxp << endl;
system("pause");
return 0;
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
Project Euler:Problem 39 Integer right triangles的更多相关文章
- 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 93 Arithmetic expressions
By using each of the digits from the set, {1, 2, 3, 4}, exactly once, and making use of the four ari ...
- Project Euler:Problem 55 Lychrel numbers
If we take 47, reverse and add, 47 + 74 = 121, which is palindromic. Not all numbers produce palindr ...
- (Problem 39)Integer right triangles
If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exact ...
- 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 32 Pandigital products
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 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 87 Prime power triples
The smallest number expressible as the sum of a prime square, prime cube, and prime fourth power is ...
- 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 ...
随机推荐
- OC学习篇之---文件的操作
今天我们来介绍OC中文件操作,在之前的文章中,已经接触到了文件的创建了,但是那不是很具体和详细,这篇文章我们就来仔细看一下OC中是如何操作文件的: 第一.首先来看一下本身NSString类给我们提供了 ...
- [Yarn] A JavaScript Package Manager
Yarn is a new JavaScript package manager that aims to be speedy, deterministic, and secure. See how ...
- 用FATFS在SD卡里写一串数字
用FATFS写SD卡,如写入数组 s[] ={1,2,3,4,5,6} 想要在txt中显示“123456” 就要把 s[0]=1+'0' 或 s[0]=1+48 或 s[0]=1+0x30 ...
- IL命令初学者要知道的事
在一个中间语言程序中,如果某一行以“.”开始,代表这是一个传输给汇编工具的指令:而不是以“.”开始的行是中间语言的代码.上图中.method是方法定义指令,定义了Main方法,参数在“()”中,IL代 ...
- [Node] Use babel-preset-env with Native Node Features and Also Use Babel Plugins
In this lesson we'll show how to setup a .babelrc file with presets and plugins. Then create npm scr ...
- Python中字符串的解压缩
今天在用Streaming-Python处理一个MapReduce程序时,发现reducer失败,原由于耗费内存达到极限了.细致查看代码时,发现有一个集合里保存着URL,而URL长度是比較长的,直接保 ...
- Xavier Initialization 的理解与推导(及实现)
在 caffe mnist tutorial 的实现中,有如下的语句: weight_filter = {type: "xavier"}; 随后的解释中指出,本实现将使用 xavi ...
- MSYS2是对MSYS的一个独立的重写,是基于当前的Cygwin和MinGW-w64重写的,以同原生的Windows软件有更好的交互性为目的
MSYS2的官网:http://sourceforge.net/projects/msys2/ 官网的描述: Description MSYS2 is an independent rewrite o ...
- html5+js压缩图片上传
最近在折腾移动站的开发,涉及到了一个手机里面上传图片.于是经过N久的折腾,找到一个插件,用法如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ...
- 【C++竞赛 C】yyy的数学公式
时间限制:1s 内存限制:32MB 问题描述 yyy遇到了一个数学问题如下: S_n=∑F(i) 其中F(i)表示i的最大奇因数 yyy的数学非常好,很快就得到了结果.现在他把问题交给你,你能解决吗? ...