ProjectEuler 009题

题目:

A Pythagorean triplet is a set of three natural numbers, a b c, for which,

a2 +
b2 = c2

For example, 32 + 42 = 9 + 16 = 25 = 52.

There exists exactly one Pythagorean triplet for which a +
b + c = 1000.
Find the product abc.

代码:


 1 #include<iostream>
2 using namespace std;
3
4 int main() {
5
6 for(int i = 1; i < 333; i++){
7 for(int j = 1; j <= 999; j++)
8 for(int k = 1; k <= 999; k++){
9 if((i*i + j*j) == (k*k) && (i+j+k) == 1000)
10 cout << i << " " << j << " " << k << endl;
11 }
12 }
13
14 system("pause");
15 return 0;
16 }

时间: 2024-10-10 00:32:01

ProjectEuler 009题的相关文章

ProjectEuler 004题

1 #include<iostream> 2 using namespace std; 3 4 int main() { 5 bool isPalindromic (int num); 6 int res = 0; 7 8 for(int i = 100; i < 1000 ; i++) 9 for(int j = 100; j < 1000; j++) { 10 if( isPalindromic(i*j) && i*j > res) 11 res = i*

ProjectEuler 003题

1 //题目:The prime factors of 13195 are 5, 7, 13 and 29. 2 //What is the largest prime factor of the number 600851475143 ? 1 #include<iostream> 2 using namespace std; 3 int main() { 4 long long N = 600851475143;//int和long都为32位,long long 为64位 5 int i;

Codeforces/TopCoder/ProjectEuler 散题笔记 (持续更新)

最近做到了一些有趣的散题,于是开个Blog记录一下吧- (如果有人想做这些题的话还是不要看题解吧-) 2017-03-16 PE 202 Laserbeam 题意:有一个正三角形的镜子屋,光线从$C$点射入,求恰好反射$12017639147$次后在$C$点射出的方案数. 题解:关于反射问题容易想到对称性,不断对称翻转正三角形,可以密铺整个平面,这样一条反射$k$次的路径对应平面上经过$k$条边的路径. 然后取$CB,CA$为基,把平面画正,就能得到一个带有平行的对角线的网格图,稍微观察一下就能

ProjectEuler 005题

题目: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? 此题就是求最小公倍数的,刚开始我考虑的太复杂,打算求出每个数的素数因子,然后去处一

projecteuler第二题

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... By considering the terms in the Fibonacci sequence whose values do not

ProjectEuler 006题

题目: The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square of the sum of the first ten natural numbers is, (1 + 2 + ... + 10)2 = 552 = 3025 Hence the difference between the sum of the squares of the first ten

projecteuler之58题Spiral primes

package com.android; public class SpiralPrimes { public static void main(String args[]) { long numPrimes = 0; long numAll = 0; long oneStart = 1; for (long i = 3; i < Long.MAX_VALUE; i = i + 2) { numAll = 2*i-1; if(isPrimes(i*i)){ numPrimes++; } if(i

LeetCode刷题-009回文数

判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数 示例 1:输入: 121输出: true 示例 2:输入: -121输出: false解释: 从左向右读, 为 -121 . 从右向左读, 为 121- .因此它不是一个回文数. 示例 3:输入: 10输出: false解释: 从右向左读, 为 01 .因此它不是一个回文数. 进阶:不将整数转为字符串来解决这个问题 1 class Solution { 2 public: 3 bool isPalindrom

[Python]小甲鱼Python视频第009课(了不起的分支和循环3)课后题及参考解答

# -*- coding: utf-8 -*- """ Created on Mon Mar 4 23:47:51 2019 @author: fengs """ """ 测试题: 0. 下面的循环会打印多少次"I Love FishC"? for i in range(0, 10, 2): print('I Love FishC') 0 2 4 6 8 5次 1.下面的循环会打印多少次"