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>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