#include #include #include using namespace std; struct S{ int e1,e2; double d; }; S s[1000000]; bool f(double p,double d,int i,int j){ while(i>p; d=modf(p,&x); f(p,d,0,999999*d)||f(p,d+1,999999*d,999999); } int main(){ int i=0; for(int a=1000;a<2000;++a){ for(int b=0;b<1000;++b){ double x=sqrt(a)+sqrt(b); double d=modf(x,&x); s[i].e1=a; s[i].e2=b; s[i].d=d; ++i; } } sort(s,s+i,[](S const&a,S const&b){return a.d>q; for(;q--;){ g(); } }