Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
暴力啊!0ms???这数据是有多弱?#include <iostream> #include <stdio.h> #include <cmath> using namespace std; bool hs(int a, int b){ if(a == 0){ return b==1; } if(b == 0){ return a==1; } if(a > b) return hs(b, a%b); return hs(a, b%a); } bool has[1000005]; int main() { int N; while(scanf("%d", &N) > 0){ if(N == -1) break; for(int i = 1; i <= N; i++) has[i] = 0; int smax = (int)sqrt(N-1.0); int gs, sy; gs = 0; sy = N; for(int s = 2; s <= smax; s++){ int tmax = s-1; int t_ = (int)sqrt(N-s*s-0.0); if(t_ < tmax) tmax = t_; for(int t = 1; t <= tmax; t++){ if((s-t)%2==0 || !hs(s,t)) continue; //cout << s <<" " << t << endl; gs++; int gou = s*s-t*t, gu = 2*s*t, f = s*s+t*t; int mxC = N/f; for(int j = 1; j <= mxC; j++){ if(!has[gou*j]){ sy--; has[gou*j] = 1; } if(!has[gu*j]){ sy--; has[gu*j] = 1; } if(!has[f*j]){ sy--; has[f*j] = 1; } } } } printf("%d %d\n", gs, sy); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator