Uva 106-fermat vs. Pythagoras (Hook number properties)

Source: Internet
Author: User

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)

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.