标签:style blog color io os for div sp on
了解一下毕达哥拉斯三元组概念= =
暴力求出所有的本源三元组即可
代码:
#include <iostream> #include <stdio.h> #include<string.h> #include<algorithm> #include<string> #include<math.h> #include<ctype.h> using namespace std; #define MAXN 10000 int n; bool vi[1000010]; int gcd(int a,int b) { return b?gcd(b,a%b):a; } int main() { #ifndef ONLINE_JUDGE freopen("shu.txt","r",stdin); #endif while(scanf("%d",&n)!=EOF) { memset(vi,0,sizeof(vi)); int ans1=0; int ans2=0; for(int i=1;;i++) { if(i*i+(i+1)*(i+1)>n) break; for(int j=i+1;;j++) { if(i*i+j*j>n) break; if((i%2)==(j%2)) continue; if(gcd(i,j)!=1) continue; int x=j*j-i*i; int y=2*i*j; int z=i*i+j*j; ans1++; for(int k=1;k*z<=n;k++) { vi[k*x]=vi[k*y]=vi[k*z]=1; } } } for(int i=1;i<=n;i++) ans2+=!vi[i]; printf("%d %d\n",ans1,ans2); } return 0; }
标签:style blog color io os for div sp on
原文地址:http://www.cnblogs.com/oneshot/p/3990978.html