Number of topics Pythagorean Pythagorean number -SCAU-1079 (original) -18,203 magic triangle

 

Number of topics Pythagorean Pythagorean number -SCAU-1079 (original) -18,203 magic triangle

Most of the Pythagorean number of topics to facilitate a lot of people are using for, then the judge is not what the square of the number, the time to do this type of variables and a lot of details to master are good, but is there a the method is to enter a number and then use mathematical methods can now answer (that is, the number of the other two methods seek out the Pythagorean)

I based on the Pythagorean theorem and an important theorem ( that is, adding minimal side is odd, then, the difference between the long side and the edge is 1, if the minimum edge is even, then the difference between the long side and the side is 2, then use the nature and the Pythagorean theorem, through the simultaneous equation)


 

 

Examples 18203 Pythagorean magic number

 

The problem there is solution to a problem

Time limit: 1000MS Memory Limit: 65535K
submit: 0 Passes: 0

Questions: Programming language problem: Not limited

Description

To give you a positive integer n, I asked whether or not a right triangle, all of its side lengths are positive integers, and n is its minimum side length.



Input Format

(One case) 
of a number n (1 ≤ n ≤ 10000) .

Output Format

Without such a right triangle, the output "NO" (without quotation marks); 
if so, outputs two numbers, the first number of Length is at right angles to one another, the second number is the side length of the hypotenuse. 
(Make sure there is only one answer)


SAMPLE INPUT

3

Sample Output

4 5
 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 int main()
 5 {
 6     int a;
 7     scanf("%d",&a);
 8     int b,c;
 9     if(a==1||a==2)
10         printf("NO");
11     else if(a%2==0)
12     {
13         b=a*a/4-1;
14         c=a*a/4+1;
15             if(a<b&&a<c)
16          printf("%d %d",b,c);
17          else
18             printf("NO");
19     }
20     else if(a%2!=0)
21     {
22         b=(a*a-1)/2;
23         c=(a*a+1)/2;
24         if(a<b&&a<c)
25      printf("%d %d",b,c);
26     
27     else
28         printf("NO");
29     }
30    // printf("%d %d",b,c);
31     return 0;
32 }
View Code

 

 
 

也就是说如果我们知道了最小边的话就可以不用for就直接用数学的公式就可以吧中边和大边给求出来了,那么加入最小边是不知道的,知道中边或者是长边的任意一个的话,该怎么求呢,

就基于上面的分析,我们还是利用了那个性质和勾股定理也是可以用数学公式发来吧其他边算出来的

如图:

 

 

 

 

思路:下面这道题目就是上面那个题目的进阶版了,因为它是要算出输入的x是短边中边长边的三种情况的

例题1079 三角形

时间限制:500MS  内存限制:65536K
提交次数:283 通过次数:82

题型: 编程题   语言: G++;GCC

 

Description

著名的数学家毕达哥拉斯可能从来都不曾想过有人居然会问他这样的一个问题:给出一个整数,存在多少个直角三角形,
它的某一条边的长度等于这个整数,而且其他边的长度也是整数。既然毕达哥拉斯不可能预见到有计算机的出现,
如果他回答不出来,那谁又能责怪他呢?但是现在既然你有了计算机,那么回答不出来就说不过去了。




输入格式

  第一行有一个整数n,代表有多少个数据(1<=n<=20)。接下来有n行,每行代表一个数据。一个数据就是一个整数ai(a<=i<=n,1<=ai<=100)。



输出格式

每个数据都必须有相应的输出。两个数据的输出之间有一个空行。
对于每一个数据,如果找不到解,则输出一个空行。如果找到解,就把符合条件的所有直角三角形输出。每个三角形占一行,输出该三角形的另外两条边,
必须先输出长边,然后一个逗号,再输出短边。两个三角形之间不能有空行,而且必须按照长边降序排列。



 

输入样例

2
20
12



 

输出样例

101,99
52,48
29,21
25,15
16,12

37,35
20,16
15,9
13,5

 

 

 

 

代码:(待完善,我优化一下)

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/SCAU-gogocj/p/11940469.html