-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
82a2840
commit 42ff06a
Showing
4 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Licensed under the MIT License. | ||
|
||
// Right Triangles with Integer Coordinates | ||
|
||
#include "../lib/euler.h" | ||
#include "../lib/euclidean.h" | ||
|
||
int main(void) | ||
{ | ||
int count = 0; | ||
clock_t start = clock(); | ||
|
||
for (int x = 1; x <= 50; x++) | ||
{ | ||
for (int y = 1; y <= 50; y++) | ||
{ | ||
int d = gcd(x, y); | ||
int min = x * d / y; | ||
int other = (50 - y) * d / x; | ||
|
||
if (other < min) | ||
{ | ||
min = other; | ||
} | ||
|
||
count += 2 * min; | ||
} | ||
} | ||
|
||
count += 50 * 50 * 3; | ||
|
||
return euler_submit(91, count, start); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Licensed under the MIT License. | ||
|
||
// Square Digit Chains | ||
|
||
#include "../lib/euler.h" | ||
|
||
int math_sum_of_square_digits(long n, int results[]) | ||
{ | ||
if (n < 568 && results[n]) | ||
{ | ||
return results[n]; | ||
} | ||
|
||
long result = 0; | ||
|
||
for (long k = n; k; k /= 10) | ||
{ | ||
int d = k % 10; | ||
|
||
result += d * d; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
int math_square_digit_chain(long m, int results[]) | ||
{ | ||
long n = m; | ||
|
||
while (n != 1 && n != 89) | ||
{ | ||
n = math_sum_of_square_digits(n, results); | ||
} | ||
|
||
return n; | ||
} | ||
|
||
int main(void) | ||
{ | ||
long count = 0; | ||
int results[568] = { 0 }; | ||
clock_t start = clock(); | ||
|
||
for (long m = 1; m < 568; m++) | ||
{ | ||
results[m] = math_square_digit_chain(m, results); | ||
|
||
if (results[m] == 89) | ||
{ | ||
count++; | ||
} | ||
} | ||
|
||
for (long m = 1; m < 10000000l; m++) | ||
{ | ||
long n = math_square_digit_chain(m, results); | ||
|
||
if (n == 89) | ||
{ | ||
count++; | ||
} | ||
} | ||
|
||
return euler_submit(91, count, start); | ||
} |