CodeForces 304A Pythagorean Theorem II 【基础】【暴力】
2017-01-23 23:31
525 查看
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
Output
Input
Output
题意就是给你一个数n,让你判断三边边长均<=n的直角三角形有多少个
开始是想找规律的,但是找了好久都没发现,最后决定暴力试一下,然后AC了。
AC代码:
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; }
相关文章推荐
- vs code golang插件记录
- Codeforces Yandex.Algorithm 2011 Round 2 D
- Ring3下无驱动移除winlogon.exe进程ctrl+alt+del,win+u,win+l三个系统热键,非屏蔽热键(子类化SAS 窗口)
- 掌握 Ajax,第 9 部分: 使用 Google Ajax Search API
- <svg/onload=prompt()>
- [golang]time.After 在select中使用的正确姿势(解决超时逻辑未生效bug)
- 倔强的驴小毛积累的go好文章
- 【通信框架】Google的开源通信框架protobuf概述
- oh my god
- brew install mongo
- go--互斥锁
- GOT表和PLT表知识详解
- django中的事务
- 采访:关于Go语言和《Go Web编程》
- go map深度拷贝
- 关于goneaway及499
- Google搜索被屏蔽的完美解决方法
- Go语言小爬虫--第一步
- Codeforces Round #388 (Div. 2)A Bachgold Problem
- 搭建Go开发及调试环境(LiteIDE + GoClipse) -- Windows篇