FZU 1669 Right-angled Triangle 毕达哥拉斯三元组

2023-10-21 22:10

本文主要是介绍FZU 1669 Right-angled Triangle 毕达哥拉斯三元组,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

  毕达哥拉斯三元组】

                                  X^2 + Y^2 = Z^2
    满足这个方程的的正整数三元组被称为毕达哥拉斯三元组。
    本原的毕达哥拉斯三元组,指如果一个毕达哥拉斯三元组x,y,z满足(x,y,z)=1,那么这个毕达哥拉斯三元组称为本原的。
    [定理]:正整数x,y,z构成一个本原毕达哥拉斯三元组且y为偶数,当且仅当互素的正整数m,n(m>n),其中m为奇数n为偶数,或者m为偶数n为奇数,并且满足
                   x=m^2-n^2;
                   y=2*m*n;
                   z=m^2+n^2;
    那么要求给定的范围内的本原毕达哥拉斯三元组数,只需对m,n分别枚举即可,然后将三元组乘以i(保证i(x+y+z)在给定的范围之内)倍,就可以求出所有满足条件的毕达哥拉斯三元组。

    满足这个方程的的正整数三元组被称为毕达哥拉斯三元组。
    本原的毕达哥拉斯三元组,指如果一个毕达哥拉斯三元组x,y,z满足(x,y,z)=1,那么这个毕达哥拉斯三元组称为本原的。
    [定理]:正整数x,y,z构成一个本原毕达哥拉斯三元组且y为偶数,当且仅当互素的正整数m,n(m>n),其中m为奇数n为偶数,或者m为偶数n为奇数,并且满足
                   x=m^2-n^2;
                   y=2*m*n;
                   z=m^2+n^2;
    那么要求给定的范围内的本原毕达哥拉斯三元组数,只需对m,n分别枚举即可,然后将三元组乘以i(保证i(x+y+z)在给定的范围之内)倍,就可以求出所有满足条件的毕达哥拉斯三元组。

 【例1】 Right-angled Triangle  [FZU 1669]  点击打开链接

Problem Description

A triangle is one of the basic shapes of geometry: a polygon with three corners or vertices and three sides or edges which are line segments. A triangle with vertices A, B, and C is denoted △ABC.
Triangles can also be classified according to their internal angles, described below using degrees of arc:
  • A right triangle (or right-angled triangle, formerly called a rectangled triangle) has one 90° internal angle (a right angle). The side opposite to the right angle is the hypotenuse; it is the longest side in the right triangle. The other two sides are the legs or catheti (singular: cathetus) of the triangle. Right triangles conform to the Pythagorean Theorem, wherein the sum of the squares of the two legs is equal to the square of the hypotenuse, i.e., a^2 + b^2 = c^2, where a and b are the legs and c is the hypotenuse.
  • An oblique triangle has no internal angle equal to 90°.
  • An obtuse triangle is an oblique triangle with one internal angle larger than 90° (an obtuse angle).
  • An acute triangle is an oblique triangle with internal angles all smaller than 90° (three acute angles). An equilateral triangle is an acute triangle, but not all acute triangles are equilateral triangles.
What we consider here is very simple. Give you the length of L, you should calculate there are how many right-angled triangles such that a + b + c ≤ L where a and b are the legs and c is the hypotenuse. You should note that the three numbers a, b and c are all integers.

Input

There are multiply test cases. For each test case, the first line is an integer L(12≤L≤2000000), indicating the length of L.

Output

For each test case, output the number of right-angled triangles such that a + b + c ≤ L where a and b are the legs and c is the hypotenuse.

Sample Input

1240

Sample Output

15

Hint

There are five right-angled triangles where a + b + c ≤ 40. That are one right-angled triangle where a = 3, b = 4 and c = 5; one right-angled triangle where a = 6, b = 8 and c = 10; one right-angled triangle where a = 5, b = 12 and c = 13; one right-angled triangle where a = 9, b = 12 and c = 15; one right-angled triangle where a = 8, b = 15 and c = 17.  

#include <stdio.h>
#include <string.h>
#include <math.h>long long gcd(long long a,long long b)
{return b==0?a:gcd(b,a%b);
}long long fun(long long a)
{long long i,j,k,tmp,x,y,z,sum=0;tmp=sqrt(a+0.0);for(i=1;i<=tmp;i++){for(j=i+1;j<=tmp;j++){if(2*j*j+2*i*j>a)break;if(i%2!=j%2){if(gcd(i,j)==1){x=j*j-i*i;y=2*i*j;z=i*i+j*j;for(k=1;;k++){if(k*(x+y+z)>a)break;sum++;}}}}}return sum;
}
int main()
{long long n;while(scanf("%lld",&n)!=EOF){long long sum=fun(n);printf("%lld\n",sum);}
}



这篇关于FZU 1669 Right-angled Triangle 毕达哥拉斯三元组的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/257287

相关文章

fzu 2277 Change 线段树

Problem 2277 Change Time Limit: 2000 mSec    Memory Limit : 262144 KB  Problem Description There is a rooted tree with n nodes, number from 1-n. Root’s number is 1.Each node has a value ai.

fzu 2275 Game KMP

Problem 2275 Game Time Limit: 1000 mSec    Memory Limit : 262144 KB  Problem Description Alice and Bob is playing a game. Each of them has a number. Alice’s number is A, and Bob’s number i

leetCode#119. Pascal's Triangle II

Description Given an index k, return the kth row of the Pascal’s triangle. For example, given k = 3, Return [1,3,3,1]. Note: Could you optimize your algorithm to use only O(k) extra space? Code

Csting Left Mid Right

 CString Left( int nCount ) const;                   //从左边1开始获取前 nCount 个字符 CString Mid( int nFirst ) const;                      //从左边第 nCount+1 个字符开始,获取后面所有的字符 CString Mid( int nFirst, int nC

第六篇——黄金分割:毕达哥拉斯如何连接数学和美学?

目录 一、背景介绍二、思路&方案三、过程1.思维导图2.文章中经典的句子理解3.学习之后对于投资市场的理解4.通过这篇文章结合我知道的东西我能想到什么? 四、总结五、升华 一、背景介绍 人眼看到的美的东西,都可以从数学这个抽象的学科中得到明确的逻辑论证;这就是数学学科神奇的地方之一 二、思路&方案 1.思维导图2.文章中经典的句子理解3.学习之后对于投资市场的理解4.通过这篇

【FZU】1921 栀子花开 线段树果题

Problem 1921 栀子花开 Accept: 216    Submit: 745 Time Limit: 1000 mSec    Memory Limit : 32768 KB Problem Description 这是一个栀子花开的季节,也是一个离别的季节,四年一千多个日日夜夜,那校园的角角落落,留下了我们沉思的身影;那上百次的成绩排名表,印证了我们深深浅浅不断进步的

【FZU】2171 防守阵地 II 线段树

Problem 2171 防守阵地 II Accept: 96    Submit: 360 Time Limit: 3000 mSec    Memory Limit : 32768 KB Problem Description 部队中总共有N个士兵,每个士兵有各自的能力指数Xi,在一次演练中,指挥部确定了M个需要防守的地点,指挥部将选择M个士兵依次进入指定地点进行防守任务,获得

【FZU】2105 Digits Count 线段树

传送门:【FZU】2105 Digits Count 题目分析:与、或、异或三种操作都是每一位相互独立的,所以可以将线段树建四棵,分别对应一位,and和or操作相当于覆盖操作,xor操作相当于反转操作,就和普通的线段树方法类似,设立两个lazy标记即可。查询的时候求得每一位的1的个数*权重(1,2,4,8),全部累加就是答案。 代码如下: #include <cst

CodeForces 407A Triangle

题意: 一个直角三角形所有点都在二维平面整点上  其中两条边长度分别为a和b  且没有任何一条边与坐标轴平行  问  这样的三角形存不存在  如果存在输出一组坐标 思路: 可以设解存在  然后先固定(0,0)这个点  这样就可以求出所有满足边长是a和b的(x,y)坐标分别放在两个数组里 注意只枚举第一、二象限即可  要不还要防止三点共线 枚举a和b的所有解  如果这确定的三个点满足

力扣刷题--1534. 统计好三元组【简单】

题目描述 给你一个整数数组 arr ,以及 a、b 、c 三个整数。请你统计其中好三元组的数量。 如果三元组 (arr[i], arr[j], arr[k]) 满足下列全部条件,则认为它是一个 好三元组 。 0 <= i < j < k < arr.length |arr[i] - arr[j]| <= a |arr[j] - arr[k]| <= b |arr[i] - arr[k]| <