poj 1305
题目:http://poj.org/problem?id=1305
题意:从 1 到 n 中找出 x y z 三个数满足:x ^ 2 + y ^ 2 = z ^ 2,且(x < y < z, x y z 两两互质)这些条件的(x,y,z)共有多少个,第二, 在 1
到 n 中不是 x,y,z任意一个或两个或三个的整数倍的数有多少
很暴力的方法,枚举 x y,然后判断z
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
typedef long long ll; bool mark[1000001]; int gcd(int a,int b) { if(!b) return a; else return gcd(b,a % b); } int main() { int i,j; int n; int num; while(~scanf("%d",&n)) { _clr(mark,false); num = 0; int temp = n / sqrt(2.0); ll tem = n * n; for(i = 1; i <= temp; i++) { for(j = i + 1; j < n; j++) { if(gcd(i,j) > 1) continue; ll kemp = i * i + j * j; int kem = sqrt(kemp * 1.0); if(kemp <= tem && kem * kem == kemp) { int flag = 0; if(gcd(i,kem) > 1 || gcd(j,kem) > 1) flag = 1; if(!flag) { num ++; for(int h = 1; h * kem <= n; h++) { mark[h * i] = true; mark[h * j] = true; mark[h * kem] = true; } } } } } int sum = 0; for(i = 1; i <= n; i++) if(!mark[i]) sum ++; printf("%d %d\n",num,sum); } return 0; }