1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| #include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
inline bool isPerfectSquare(const unsigned long int& number);
const unsigned long int MAX(10000);
int main()
{
vector<unsigned long int> x, min;
cout << "Investigate the Diophantine equation x^2 - Dy^2 = 1.\n";
for(unsigned long int D(1); D <= 1000; ++D)
{
if(!isPerfectSquare(D))
{
for(unsigned long int y(1); y <= MAX; ++y)
{
if(isPerfectSquare((1+(D*y*y))))
{
min.push_back(sqrt((1+(D*y*y))));
}
}
x.push_back(*min_element(min.begin(), min.end()));
min.clear();
}
}
cout << x.size() << endl;// ça devrait être égale à 1000
cout << *max_element(x.begin(), x.end()) << endl;
cout << "Solution : " << distance(x.begin(), max_element(x.begin(), x.end()))+1 << endl;
return 0;
}
inline bool isPerfectSquare(const unsigned long int& number)
{
unsigned long int square(number), rootSquare(sqrt(number));
if(square == rootSquare*rootSquare) return true;
return false;
} |
Partager