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

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

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

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

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

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

  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 87 Prime power triples

    The smallest number expressible as the sum of a prime square, prime cube, and prime fourth power is ...

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

随机推荐

  1. 短网址ShortUrl的算法

    场景: 我们在新浪微博上公布网址的时候.微博会自己主动判别网址.并将其转换.比如:http://t.cn/hrYnr0. 为什么要这样做的,原因我想有这样几点: 1.微博限制字数为140字一条,那么假 ...

  2. 使用PHP实现双向队列

    使用PHP实现双向队列 一.总结 就是几个array函数 push pop shift unshift n. 移动:变化:手段:轮班 vi. 移动:转变:转换 vt. 转移:改变:替换 二.使用PHP ...

  3. 每日技术总结:flex,选项卡,classList,

    1.Flex布局子元素垂直居中 给父元素添加以下样式: .parent { display: flex; align-items: center; } 2.js面向对象的选项卡 见另一篇文章 js面向 ...

  4. 【例题 6-3 UVA - 442】Matrix Chain Multiplication

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用栈来处理一下表达式就好. 因为括号是一定匹配的.所以简单很多. ab x bc会做abc次乘法. [代码] #include< ...

  5. 一次性能优化将filter转换

    有一条SQL性能有问题,在运行计划中发现filter.遇到它要小心了,类似于nestloop.我曾经的blog对它有研究探索运行计划中filter的原理.用exists极易引起filter. 优化前: ...

  6. std::的概念与作用

    std:: 当中std是名称空间,防止反复.比如说很多人给函数取名可能都叫f1():你使用的时候就可能造成问题.如果各人均把自己的f1()放进自己的名称空间.我们在使用的时候带上名称空间就不会有问题. ...

  7. Oracle-18-select语句初步&amp;SQL中用算术表达式&amp;别名的使用&amp;连接运算符%distinct&amp;where子句

    一.一般SELECT语句的格式例如以下: 1.查询指定表的全部列 select * from 表名 [where 条件] [group by 分组列名] [having 聚合函数] [order by ...

  8. 使用GDB进行嵌入式远程调试

    PC主机:Ubuntu 10.4 目标板:TQ2440开发板,linux内核2.6.30 NOTE:为了使用gdb进行调试,强烈建议使用nfs服务,否则调试会非常麻烦. 使用nfs服务可以参考:S3C ...

  9. php 小程序获取渠道二维码 保存

    function ppost($url,$arr){ $post_data = json_encode($arr); $url=$url; $ch = curl_init(); curl_setopt ...

  10. Spring web 工具类 WebApplicationContextUtils

    概述 Spring web 的工具类 WebApplicationContextUtils 位于包 org.springframework.web.context.support 是访问一个Servl ...