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

 Problem 1669 Right-angled Triangle

Accept: 94    Submit: 183
Time Limit: 1000 mSec    Memory Limit : 32768 KB

 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.

 Source

FOJ月赛-2008年11月




题意:
给你一个L,求出(a,b,c)组合成直角三角形的总数。a+b+c<=L,且(a,b,c)和(a,c,b)算同一种。

POINT:

毕达哥拉斯三元组:有正整数三元组xyz,满足x^2+y^2=z^2,这样的三元组被称为毕达哥拉斯三元组。特殊的,若gcd(x,y,z)=1,那么这个毕达哥拉斯三元组是本原的。


定理:正整数x,y,z构成一个本原毕达哥拉斯三元组且y为偶数,当且仅当存在互素的正整数mn(m>n),其中m为奇数n为偶数,或者m为偶数n为奇数,并且满足:

                                           x=m^2-n^2

                                           y=2mn

                                           z=m^2+n^2


求出本原毕达哥拉斯三元组,在同乘1 2 3 4,判断大不大于L。

#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
int gcd(int a,int b)
{
    return b==0?a:gcd(b,a%b);
}
int main()
{
    int t;
    while(~scanf("%d",&t))
    {
        int max=(int)sqrt(t)+2;
        int ans=0;
        for(int n=1;n<=max;n++)
        {
            for(int m=n+1;m<=max;m++)
            {
                if((m+n)%2!=1) continue;
                if(2*m*m+2*m*n>t) break;
                if(gcd(m,n)==1)
                {
                    int x=m*m-n*n;
                    int y=2*m*n;
                    int z=m*m+n*n;
                    for(int i=1;;i++)
                    {
                        if(i*(x+y+z)<=t) ans++;
                        else break;
                    }
                }
            }
        }
        printf("%d\n",ans);
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值