Pythagorean Theorem II

Source: Internet
Author: User
A. Pythagorean Theorem IItime limit per test

3 seconds

Memory limit per test

256 megabytes

Input

Standard input

Output

Standard output

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 (
Two sides that meet at a right angle ).

The theorem can be written as an equation relating the lengths of the sidesA,BAndC,
Often called the Pythagorean equation:

A 2 cores + CoresB2 bytes = bytesC2

WhereCRepresents the length of the hypotenuse, andAAndBRepresent
The lengths of the other two sides.

GivenN, Your task is to count how many right-angled triangles with side-lengthsA,BAndCThat
Satisfied an inequality 1 limit ≤ limitALimit ≤ limitBLimit ≤ limitCLimit ≤ limitN.

Input

The only line contains one integerN(1 digit ≤ DigitNLimit ≤ limit 104)
We mentioned above.

Output

Print a single integer-the answer to the problem.

Sample test (s) input
5
Output
1
Input
74
Output
35

Idea: 10 ^ 8MLE, two points + enumeration n. Enumerative n is a good posture. Do not look for map for the free time of table creation, or it will die very quickly.

In addition, Yu GE's direct root code is actually the simplest and most effective method.

#include <algorithm>#include <iostream>#include <iomanip>#include <cstdio>#include <map>#include <cstdlib>#include <cstring>typedef long long ll;#defineclr(a)memset((a),0,sizeof (a))#definerep(i,a,b)for(int i=(a);i<(int)(b);i++)#defineper(i,a,b)for(int i=((a)-1);i>=(int)(b);i--)#defineinf0x7ffffff#defineeps1e-6using namespace std;int mm[10005];int num[10005];/*bool find(int a,int b,int  key){    int mid=(a+b)/2;      if(mm[mid]==key){       return 1;                }     if(a==b-1)return 0;//cause I sent the mid ,not the mid-1 or mid+1。     if(mm[mid]>key){      return find(a,mid,key);         }        else{      return find(mid,b,key);         }}*/// the more adequate 'find' functionbool find(int a,int b,int  key){    if(a>b)return 0;    int mid=(a+b)/2;      if(mm[mid]==key){       return 1;                }     if(mm[mid]>key){      return find(a,mid-1,key);         }        else{      return find(mid+1,b,key);         }}int main(){    for(int i=1;i<=10000;i++){      mm[i]=i*i;      }  for(int i=10000;i>=1;i--){     for(int j=i-1;j>=1;j--){        int tt=i*i-j*j;        if(tt>j*j)break;        if(find(1,10000,tt)){                    num[i]++;                           }                 }          }  int n;  scanf("%d",&n);  int sum=0;  for(int i=1;i<=n;i++){      sum+=num[i];         }  printf("%d\n",sum);   //system("pause");  return 0;}

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.