CodeForces 304A Pythagorean Theorem II 【基础】【暴力】

来源:互联网 发布:美国歌手prince 知乎 编辑:程序博客网 时间:2024/05/22 10:42

Description:

In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:

In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).

The theorem can be written as an equation relating the lengths of the sides a, b and c, often called the Pythagorean equation:

a2 + b2 = c2

where c represents the length of the hypotenuse, anda andb represent the lengths of the other two sides.

Given n, your task is to count how many right-angled triangles with side-lengthsa,b andc that satisfied an inequality1 ≤ a ≤ b ≤ c ≤ n.

Input

The only line contains one integer n (1 ≤ n ≤ 104) as we mentioned above.

Output

Print a single integer — the answer to the problem.

Examples
Input
5
Output
1
Input
74
Output
35


题意就是给你一个数n,让你判断三边边长均<=n的直角三角形有多少个

开始是想找规律的,但是找了好久都没发现,最后决定暴力试一下,然后AC了。

AC代码:

#include <cstdlib>#include <iostream>#include <cstdio>#include <cstring>#include <cmath>using namespace std;int main(){    int n, ans;    while(~scanf("%d",&n))    {        ans = 0;        for(int i = 1; i <= n; ++i)            for(int j = i; j <= n; ++j)            {                int tem = i * i + j * j;                int tem1 = (sqrt(tem) + 0.5);                if((tem1 * tem1 == tem) && (tem1 <= n) && ((i + j) > tem1))                {                    //cout<<tem1<<endl;                    ans++;                    //cout<<"i="<<i<<"  j="<<j<<"  tem="<<tem<<endl;                }            }        cout << ans << endl;    }    return 0;}


0 0
原创粉丝点击