10,793 angle Shape

Source: Internet
Author: User

Time limit : 500MS Memory limit : 65536K commits: 283 number of passes :

Question types : programming language : C + +; C

Description

The famous mathematician Pythagoras may have never thought that someone would actually ask him such a question: Give an integer, how many right triangle exist, the length of one of its edges equals this integer, and the length of the other side is an integer. Since Pythagoras could not have foreseen the advent of computers, who could blame him if he could not answer? But now that you have a computer, it is not justified to answer it.

Input format

The first line has an integer n, which represents how many data (1<=n<=20). Next, there are n rows, each representing a single row of data. A data is an integer a I (A<=i<=n,1<=ai<=100).

Output format

Each data must have a corresponding output. There is a blank line between the outputs of the two data. Do not add blank lines after the last test data output. For each data, if no solution is found, a blank line is output. If the solution is found, all right triangle that match the condition are output. Each triangle occupies one row, and the other two edges of the triangle are output, and you must first output a long edge, then a comma, and then output the short edge. There can be no blank lines between the two triangles, and must be arranged in descending order of long edges.

Input sample

2

20

12

Output sample

101,99

52,48

29,21

25,15

16,12

37,35

20,16

15,9

13,5

Time:124ms

#include"stdio.h"#include"math.h"intMain () {intN,i,c,leap,k1,k2,k3,k4,k5; scanf ("%d",&N);  while(n--)/*Case number, use while (x--) more convenient*/{Leap=1; scanf ("%d",&c); K1=pow (c,2); /*because, c<=100, after calculation, when c=100, the longest side is 2501*/         for(i=2501; i>=3; i--)/*I descending because the topic requires the output to be in descending order of long edge*/        {            /*discussion of three different cases respectively*/K2=pow (I,2); K3=(int) sqrt (k1-K2); K4=(int) sqrt (k1+K2); K5=(int) sqrt (k2-K1); /*K3, K4, K5 should be satisfied greater than 0, should be in the calculation process may K3,k4,k5 is negative i>k3 is because the topic requires long side in front*/            if(Pow (K3,2) +k2==k1&&k3>0&&i>K3) Leap=0, printf ("%d,%d\n", I,K3); if(Pow (K4,2) ==k1+k2&&k4>0&&i>K4) Leap=0, printf ("%d,%d\n", I,K4); if(Pow (K5,2) +k1==k2&&k5>0&&i>K5) Leap=0, printf ("%d,%d\n", I,K5); }        if(Leap) Putchar ('\ n'); Putchar ('\ n'); }    return 0;}

* The core of this problem is through the input C, plus a loop i,

by K (double) =sqrt(c*c-i*i), and then the k - rounding

If the completion of the K to meet the hook-type, then k for the request * /

10,793 angle Shape

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.