diff --git a/C/p051.c b/C/p051.c index 12a3f1a..72eb504 100644 --- a/C/p051.c +++ b/C/p051.c @@ -30,7 +30,11 @@ int main(int argc, char **argv) clock_gettime(CLOCK_MONOTONIC, &start); /* N set to 1000000 as a reasonable limit, which turns out to be enough.*/ - primes = sieve(N); + if((primes = sieve(N)) == NULL) + { + fprintf(stderr, "Error! Sieve function returned NULL\n"); + return 1; + } /* Checking only odd numbers with at least 4 digits.*/ for(i = 1001; i < N; i += 2) diff --git a/C/p060.c b/C/p060.c index 17a1dcf..15ecf0c 100644 --- a/C/p060.c +++ b/C/p060.c @@ -24,7 +24,11 @@ int main(int argc, char **argv) clock_gettime(CLOCK_MONOTONIC, &start); - primes = sieve(N); + if((primes = sieve(N)) == NULL) + { + fprintf(stderr, "Error! Sieve function returned NULL\n"); + return 1; + } /* Straightforward brute force approach.*/ for(p1 = 3; p1 < N && !found; p1 += 2) diff --git a/Python/p003.py b/Python/p003.py index cb395c6..6c953fe 100644 --- a/Python/p003.py +++ b/Python/p003.py @@ -26,7 +26,7 @@ def max_prime_factor(num): # If num is divisible by i and i is prime, find largest # prime factor of num/i. - while 1: + while True: if num % i == 0: if is_prime(i): return max_prime_factor(num//i) diff --git a/Python/p038.py b/Python/p038.py index 7412b68..f8804c0 100644 --- a/Python/p038.py +++ b/Python/p038.py @@ -33,7 +33,7 @@ def main(): n = 0 j = 1 - while 1: + while True: tmp = i * j n = n + tmp j = j + 1 diff --git a/Python/p041.py b/Python/p041.py index 09996fb..dab0a7e 100644 --- a/Python/p041.py +++ b/Python/p041.py @@ -8,15 +8,6 @@ from timeit import default_timer from projecteuler import is_pandigital, is_prime -def count_digits(n): - i = 0 - - while n > 0: - i = i + 1 - n = n // 10 - - return i - def main(): start = default_timer() @@ -28,7 +19,7 @@ def main(): i = 7654321 while(i > 0): - if is_pandigital(i, count_digits(i)) and is_prime(i): + if is_pandigital(i, len(str(i))) and is_prime(i): break # Skipping the even numbers. i = i - 2 diff --git a/Python/p052.py b/Python/p052.py index 2016c53..6a8b443 100644 --- a/Python/p052.py +++ b/Python/p052.py @@ -35,7 +35,7 @@ def main(): i = 1 # Brute force approach, try every integer number until the desired one is found. - while 1: + while True: if have_same_digits(i, 2*i) and have_same_digits(i, 3*i) and have_same_digits(i, 4*i) and\ have_same_digits(i, 5*i) and have_same_digits(i, 6*i): break diff --git a/Python/p057.py b/Python/p057.py index cc4148c..7f9e681 100644 --- a/Python/p057.py +++ b/Python/p057.py @@ -18,15 +18,6 @@ from timeit import default_timer -def count_digits(n): - count = 0 - - while n > 0: - n = n // 10 - count = count + 1 - - return count - def main(): start = default_timer() @@ -41,7 +32,7 @@ def main(): d = n + d n = n + d2 - if count_digits(n) > count_digits(d): + if len(str(n)) > len(str(d)): count = count + 1 end = default_timer() diff --git a/Python/p058.py b/Python/p058.py index b7c088e..853f2d5 100644 --- a/Python/p058.py +++ b/Python/p058.py @@ -33,7 +33,7 @@ def main(): count = 0 diag = 5 - while 1: + while True: i = i + step if is_prime(i):