51nod 1165 number of full-edge right triangle

Source: Internet
Author: User

Topic Link: Portal

Test instructions

Given the perimeter of a right triangle, how many of these right triangle

Analysis:

The three-side length is a,b,c A <= B <= C. A + B + C = l,a^2 + b^2 = c^2

Two equations are associated with elimination of C:A + B + sqrt (a^2 + b^2) = l;

B = (l^2-2*l*A)/(2*l-2*a)

Set t = l-a. B = l-l^2/(2*t);

Because 0 < a < L/2; and b is a positive integer.

Therefore 2*t must be a factor of l^2 and this factor must contain a multiple of 2.

According to the above inequalities can be solved sqrt (2) *l < T < l*2

The code is as follows:

#include <iostream> #include <cstdio> #include <cmath> #include <set> #include <cstring> using namespace Std;const int maxn = 1e7+10;typedef long long ll;int p[maxn/10],cnt;bool vis[maxn];int fac[1000],tot;int N    Um[1000];void init () {cnt=0;    memset (vis,0,sizeof (VIS));            for (int i=2;i<maxn;i++) {if (!vis[i]) {p[cnt++]=i;        for (int j=i+i;j<maxn;j+=i) vis[j]=1;    }}}void get (LL x) {tot=0;    memset (num,0,sizeof (num));            for (int i=0;i<cnt&&p[i]*p[i]<=x;i++) {if (x%p[i]==0) {fac[tot]=p[i];            while (x%p[i]==0) num[tot]++,x/=p[i];            num[tot]*=2;        tot++; }} if (x>1) fac[tot]=x,num[tot++]=2;} int ans = 0; LL n;set<ll>st;void dfs (int id,ll val) {if (id>=tot| |    Val>=2*n) return;    if (VAL&GT;SQRT (2) *n&&val<2*n&&val%2==0) St.insert (Val);        if (num[id]>0) {num[id]--;        DFS (Id,val*fac[id]); DfsId+1,val*fac[id]);    num[id]++; } dfs (id+1,val);}    int main () {init ();    int t;    scanf ("%d", &t);        while (t--) {scanf ("%lld", &n);        Ans = 0;        if (n%2) {puts ("0"); continue;}        Get (n);        St.clear ();        DFS (0,1);    printf ("%d\n", St.size ()); } return 0;}


51nod 1165 number of full-edge right triangle

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.