Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- double __forceinline GetMinMaxX1(double a,double b, double c, double d, double e, double f)
- {
- return (4*c*d - 2*b*e - sqrt((-4*c*d + 2*b*e)*(-4*c*d + 2*b*e) -
- 4*(b*b - 4*a*c)*(e*e - 4*c*f)))/(2.*(b*b - 4*a*c));
- }
- double __forceinline GetMinMaxX2(double a,double b, double c, double d, double e, double f)
- {
- return (4*c*d - 2*b*e + sqrt((-4*c*d + 2*b*e)*(-4*c*d + 2*b*e) -
- 4*(b*b - 4*a*c)*(e*e - 4*c*f)))/(2.*(b*b - 4*a*c));
- }
- int __forceinline GetMinX(double a,double b, double c, double d, double e, double f)
- {
- return static_cast<int>(floor(min(GetMinMaxX1(a,b,c,d,e,f),GetMinMaxX2(a,b,c,d,e,f))));
- }
- int __forceinline GetMaxX(double a,double b, double c, double d, double e, double f)
- {
- return static_cast<int>(ceil(max(GetMinMaxX1(a,b,c,d,e,f),GetMinMaxX2(a,b,c,d,e,f))));
- }
- double __forceinline GetLower(double a,double b, double c, double d, double e, double f, double x)
- {
- return (-e - b*x - sqrt((e + b*x)*(e + b*x) - 4*c*(f + d*x + a*x*x)))/(2*c);
- }
- double __forceinline GetUpper(double a,double b, double c, double d, double e, double f, double x)
- {
- return (-e - b*x + sqrt((e + b*x)*(e + b*x) - 4*c*(f + d*x + a*x*x)))/(2*c);
- }
- bool __forceinline IsInt(double i)
- {
- static double intpart;
- return modf(i, &intpart) == 0.0;
- }
- bool __forceinline IsEllipse(double a,double b, double c, double d, double e, double f)
- {
- return (b*b-4*a*c) < 0;
- }
- bool __forceinline IsEvaluable(double a,double b, double c, double d, double e, double f, double x)
- {
- return ((e + b*x)*(e + b*x) - 4*c*(f + d*x + a*x*x)) >= 0;
- }
- int __forceinline GetNumLatticePoints(double a, double b, double c, double d, double e, double f)
- {
- if(!IsEllipse(a,b,c,d,e,f))
- return 0;
- int iMin = GetMinX(a,b,c,d,e,f);
- int iMax = GetMaxX(a,b,c,d,e,f);
- int iLattice = 0;
- for(int i = iMin; i <= iMax; ++i)
- {
- double x = static_cast<double>(i);
- if(IsEvaluable(a,b,c,d,e,f,x))
- {
- double dLower = GetLower(a,b,c,d,e,f,x);
- double dUpper = GetUpper(a,b,c,d,e,f,x);
- if(IsInt(dLower))
- ++iLattice;
- if(dLower != dUpper && IsInt(dUpper))
- ++iLattice;
- }
- }
- return iLattice;
- }
- int main()
- {
- for(double a = -20; a <= 20; ++a)
- {
- for(double b = -20; b <= 20; ++b)
- {
- for(double c = -20; c <= 20; ++c)
- {
- for(double d = -20; d <= 20; ++d)
- {
- for(double e = -20; e <= 20; ++e)
- {
- for(double f = -20; f <= 20; ++f)
- {
- if(GetNumLatticePoints(a,b,c,d,e,f) == 17)
- {
- cout << "a = " << a << "; b = " << b << "; c = " << c << "; d = " << d << "; e = " << e << "; f = " << f << endl;
- }
- }
- }
- }
- }
- }
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment