Topic Link: Click to open the link
Test instructions: Gives the number of solutions (n,x^2+y^2=z^2) that are less than or equal to n and the numbers of less than N to remove all the solutions (including the non-reciprocity) that have been used.
Degree Niang gives the definition of the number of hooks: only consider the solution of the reciprocity, give the number of tick formula A=2*m*n, B=m*m-n*n, c=m*m+n*n; Enumeration M,n, complexity O (log (n) ^2)
#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include < string> #include <cctype> #include <vector> #include <cstdio> #include <cmath> #include < queue> #include <stack> #include <map> #include <set> #define MAXN 1000003#define _ll __int64#define ll long long#define INF 0x3f3f3f3f#define Mod 10000007#define pp pair<int,int> #define ull unsigned long longusing na Mespace std;int n;int gcd (int a,int b) {return b==0?a:gcd (b,a%b);} BOOL Vis[maxn];void Solve () {memset (vis,0,sizeof (VIS)), int m= (int) sqrt (n+1), num=0,p=0;for (int i=1;i<=m;i++) {for ( int j=i+1;j<=m;j++) {int c=i*i+j*j;if (c>n) break;int a=2*i*j,b=j*j-i*i;if (gcd (b), c) gcd)!=1 1;vis[b]=1;vis[c]=1;num++;for (int k=2;k*c<=n;k++) {vis[a*k]=vis[b*k]=vis[c*k]=1;}}} for (int i=1;i<=n;i++) if (!vis[i]) p++;p rintf ("%d%d\n", num,p);} int main () {while (~SCANF ("%d", &n)) {Solve ();} return 0;}
Uva 106-fermat vs. Pythagoras (Hook number properties)