commit 0a6a0bf18de14194c429e70adc682d221ac19f0c
parent b1fa56b363c7c8d5a5d55a85c8f987078a4572a5
Author: mpizzzle <m@michaelpercival.xyz>
Date: Sun, 27 Sep 2020 21:15:45 +0100
euler 95 complete badly, still working on it
Diffstat:
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/Euler_95.cpp b/Euler_95.cpp
@@ -17,9 +17,10 @@ int sumProperDivisors(int n)
int Euler::AmicableChains()
{
- int one_million = 100000;
+ int one_million = 1000000;
int longest = 0;
int solution = 0;
+
std::vector<int> cache(one_million + 1, 0);
for (int i = 0; i <= one_million; ++i) {
@@ -37,11 +38,6 @@ int Euler::AmicableChains()
std::cout << n << ": ";
while(true) {
- if (fast_ptr <= 1 || slow_ptr > one_million || fast_ptr > one_million) {
- std::cout << "no bueno." << std::endl;
- break;
- }
-
fast_ptr = cache[fast_ptr];
if (fast_ptr <= 1 || fast_ptr > one_million) {
@@ -84,6 +80,11 @@ int Euler::AmicableChains()
slow_ptr = cache[slow_ptr];
fast_ptr = cache[fast_ptr];
+
+ if (fast_ptr <= 1 || slow_ptr > one_million || fast_ptr > one_million) {
+ std::cout << "no bueno." << std::endl;
+ break;
+ }
}
}