;; -*- Mode:Lisp; Syntax:ANSI-Common-LISP; Coding:us-ascii-unix; fill-column:158 -*-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;; @file      exp-Euler.lisp
;; @author    Mitch Richling <https://www.mitchr.me>
;; @brief     Solutions to Project Euler Problems.@EOL
;; @std       Common Lisp
;; @copyright 
;;  @parblock
;;  Copyright (c) 2011,2015, Mitchell Jay Richling <https://www.mitchr.me> All rights reserved.
;;
;;  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
;;
;;  1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
;;
;;  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
;;     and/or other materials provided with the distribution.
;;
;;  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software
;;     without specific prior written permission.
;;
;;  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
;;  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
;;  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
;;  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
;;  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
;;  DAMAGE.
;;  @endparblock
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=1
;; GCA: 1. 233168
;; Problem 1 (SOLVED:VERIFIED:POSTED)
;; 05 October 2001
;; 
;; If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
;; 
;; Find the sum of all the multiples of 3 or 5 below 1000.

;; Direct method
(loop for j below 1000
      when (or (zerop (mod j 3)) (zerop (mod j 5)))
      sum j)
;; RESULT: 233168

;; Sum up the integer multiples of 3 and the integer multiples of 5, and subtract the intersection (multiples of 15)

(+ (* 3   (loop for j below 1000/3  by 1 sum j))
   (* 5   (loop for j below 1000/5  by 1 sum j))
   (* -15 (loop for j below 1000/15 by 1 sum j)))
;; RESULT: 233168

;; Use the formual N*(N-1)/2 to do teh above 
(+ (*   3/2 332 (1- 332))
   (*   5/2 199 (1- 199))
   (* -15/2  66 (1-  66)))
;; RESULT: 231168

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=2
;; GCA: 2. 4613732
;; Problem 2 (SOLVED:VERIFIED:POSTED)
;; 19 October 2001
;; 
;; Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
;; 
;; 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
;; 
;; By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

(loop with (lst cur) = '(1 1)
      while (<= cur 4000000)
      when (evenp cur)
      sum cur
      do (psetf lst cur
                cur (+ lst cur)))
;; RESULT: 4613732

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=3
;; GCA: 3. 6857
;; Problem 3 (SOLVED:VERIFIED:POSTED)
;; 02 November 2001
;; 
;; The prime factors of 13195 are 5, 7, 13 and 29.
;; 
;; What is the largest prime factor of the number 600851475143 ?

(multiple-value-bind (fac left)
    (mjr_prime_small-prime-factorization 600851475143)
  (if (= 1 left)
      (car (sort (mapcar #'car fac) #'>))))
;; RESULT: 6857

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=4
;; GCA: 4. 906609
;; Problem 4 (SOLVED:VERIFIED:POSTED)
;; 16 November 2001
;; 
;; A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is $9009 = 91 x 99$.
;; 
;; Find the largest palindrome made from the product of two 3-digit numbers.

(loop for a from 100 upto 999
      maximize (loop for b from 100 upto 999
                     for p = (* a b)
                     for s = (format nil "~d" p)
                     when (equalp s (reverse s))
                     maximize p))
;; RESULT: 906609

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=5
;; GCA: 5. 232792560
;; Problem 5 (SOLVED:VERIFIED:POSTED)
;; 30 November 2001
;; 
;; 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
;; 
;; What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

(let ((the-num 1)
      (the-fac (make-array 21 :initial-element 0)))
  (loop for j from 1 upto 20
        for jfac = (mjr_prime_small-prime-factorization j)
        do (loop for (f . e) in jfac
                 when (> e (aref the-fac f))
                 do (setf (aref the-fac f) e)))
  (loop for e across the-fac
        for f from 0
        when (not (zerop e))
        do (setf the-num (* the-num (expt f e))))
  the-num)
;; RESULT: 232792560

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=6
;; GCA: 6. 25164150
;; Problem 6 (SOLVED:VERIFIED:POSTED)
;; 14 December 2001
;; 
;; The sum of the squares of the first ten natural numbers is, $1^2 + 2^2 + ... + 10^2 = 385$
;; 
;; The square of the sum of the first ten natural numbers is, $(1 + 2 + ... + 10)^2 = 55^2 = 3025$
;; 
;; Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is $3025 - 385 = 2640$.
;; 
;; Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.

;; Direct method
(let ((n 100))
  (- (expt (loop for i from 1 upto n
                 sum i)
           2)
     (loop for i from 1 upto n
           sum (* i i))))
;; RESULT: 25164150

;; with some math....
;;  ratsimp(n*(n+1)*(2*n+1)/6 - (n*(n+1)/2)^2);
;;
;;                                4      3      2
;;                             3 n  + 2 n  - 3 n  - 2 n
;; (%o4)                     - ------------------------
;;                                        12
(let ((n 100))
  (/ (- (- (+ (* 3 (expt n 4)) (* 2 (expt n 3))) (* 3 (expt n 2)))
        (* 2 n))
     12))
;; RESULT: 25164150


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=7
;; GCA: 7. 104743
;; Problem 7 (SOLVED:VERIFIED:POSTED)
;; 28 December 2001
;; 
;; By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
;; 
;; What is the 10,001st prime number?

(mjr_prime_nth-small-prime 10000)
;; RESULT: 104743

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=8
;; GCA: 8. 40824
;; Problem 8 (SOLVED:VERIFIED:POSTED)
;; 11 January 2002
;; 
;; Find the greatest product of five consecutive digits in the 1000-digit number.
;; 
;; 73167176531330624919225119674426574742355349194934
;; 96983520312774506326239578318016984801869478851843
;; 85861560789112949495459501737958331952853208805511
;; 12540698747158523863050715693290963295227443043557
;; 66896648950445244523161731856403098711121722383113
;; 62229893423380308135336276614282806444486645238749
;; 30358907296290491560440772390713810515859307960866
;; 70172427121883998797908792274921901699720888093776
;; 65727333001053367881220235421809751254540594752243
;; 52584907711670556013604839586446706324415722155397
;; 53697817977846174064955149290862569321978468622482
;; 83972241375657056057490261407972968652414535100474
;; 82166370484403199890008895243450658541227588666881
;; 16427171479924442928230863465674813919123162824586
;; 17866458359124566529476545682848912883142607690042
;; 24219022671055626321111109370544217506941658960408
;; 07198403850962455444362981230987879927244284909188
;; 84580156166097919133875499200524063689912560717606
;; 05886116467109405077541002256983155200055935729725
;; 71636269561882670428252483600823257530420752963450

(loop for (a b c d e) on '(7 3 1 6 7 1 7 6 5 3 1 3 3 0 6 2 4 9 1 9 2 2 5 1 1 9 6 7 4 4 2 6 5 7 4 7 4 2 3 5 5 3 4 9 1 9 4 9 3 4 9 6 9 8 3 5 2 0 3 1 2
                           7 7 4 5 0 6 3 2 6 2 3 9 5 7 8 3 1 8 0 1 6 9 8 4 8 0 1 8 6 9 4 7 8 8 5 1 8 4 3 8 5 8 6 1 5 6 0 7 8 9 1 1 2 9 4 9 4 9 5 4 5
                           9 5 0 1 7 3 7 9 5 8 3 3 1 9 5 2 8 5 3 2 0 8 8 0 5 5 1 1 1 2 5 4 0 6 9 8 7 4 7 1 5 8 5 2 3 8 6 3 0 5 0 7 1 5 6 9 3 2 9 0 9
                           6 3 2 9 5 2 2 7 4 4 3 0 4 3 5 5 7 6 6 8 9 6 6 4 8 9 5 0 4 4 5 2 4 4 5 2 3 1 6 1 7 3 1 8 5 6 4 0 3 0 9 8 7 1 1 1 2 1 7 2 2
                           3 8 3 1 1 3 6 2 2 2 9 8 9 3 4 2 3 3 8 0 3 0 8 1 3 5 3 3 6 2 7 6 6 1 4 2 8 2 8 0 6 4 4 4 4 8 6 6 4 5 2 3 8 7 4 9 3 0 3 5 8
                           9 0 7 2 9 6 2 9 0 4 9 1 5 6 0 4 4 0 7 7 2 3 9 0 7 1 3 8 1 0 5 1 5 8 5 9 3 0 7 9 6 0 8 6 6 7 0 1 7 2 4 2 7 1 2 1 8 8 3 9 9
                           8 7 9 7 9 0 8 7 9 2 2 7 4 9 2 1 9 0 1 6 9 9 7 2 0 8 8 8 0 9 3 7 7 6 6 5 7 2 7 3 3 3 0 0 1 0 5 3 3 6 7 8 8 1 2 2 0 2 3 5 4
                           2 1 8 0 9 7 5 1 2 5 4 5 4 0 5 9 4 7 5 2 2 4 3 5 2 5 8 4 9 0 7 7 1 1 6 7 0 5 5 6 0 1 3 6 0 4 8 3 9 5 8 6 4 4 6 7 0 6 3 2 4
                           4 1 5 7 2 2 1 5 5 3 9 7 5 3 6 9 7 8 1 7 9 7 7 8 4 6 1 7 4 0 6 4 9 5 5 1 4 9 2 9 0 8 6 2 5 6 9 3 2 1 9 7 8 4 6 8 6 2 2 4 8
                           2 8 3 9 7 2 2 4 1 3 7 5 6 5 7 0 5 6 0 5 7 4 9 0 2 6 1 4 0 7 9 7 2 9 6 8 6 5 2 4 1 4 5 3 5 1 0 0 4 7 4 8 2 1 6 6 3 7 0 4 8
                           4 4 0 3 1 9 9 8 9 0 0 0 8 8 9 5 2 4 3 4 5 0 6 5 8 5 4 1 2 2 7 5 8 8 6 6 6 8 8 1 1 6 4 2 7 1 7 1 4 7 9 9 2 4 4 4 2 9 2 8 2
                           3 0 8 6 3 4 6 5 6 7 4 8 1 3 9 1 9 1 2 3 1 6 2 8 2 4 5 8 6 1 7 8 6 6 4 5 8 3 5 9 1 2 4 5 6 6 5 2 9 4 7 6 5 4 5 6 8 2 8 4 8
                           9 1 2 8 8 3 1 4 2 6 0 7 6 9 0 0 4 2 2 4 2 1 9 0 2 2 6 7 1 0 5 5 6 2 6 3 2 1 1 1 1 1 0 9 3 7 0 5 4 4 2 1 7 5 0 6 9 4 1 6 5
                           8 9 6 0 4 0 8 0 7 1 9 8 4 0 3 8 5 0 9 6 2 4 5 5 4 4 4 3 6 2 9 8 1 2 3 0 9 8 7 8 7 9 9 2 7 2 4 4 2 8 4 9 0 9 1 8 8 8 4 5 8
                           0 1 5 6 1 6 6 0 9 7 9 1 9 1 3 3 8 7 5 4 9 9 2 0 0 5 2 4 0 6 3 6 8 9 9 1 2 5 6 0 7 1 7 6 0 6 0 5 8 8 6 1 1 6 4 6 7 1 0 9 4
                           0 5 0 7 7 5 4 1 0 0 2 2 5 6 9 8 3 1 5 5 2 0 0 0 5 5 9 3 5 7 2 9 7 2 5 7 1 6 3 6 2 6 9 5 6 1 8 8 2 6 7 0 4 2 8 2 5 2 4 8 3
                           6 0 0 8 2 3 2 5 7 5 3 0 4 2 0 7 5 2 9 6 3 4 5 0)
      when (and a b c d e)
      maximize (* a b c d e))
;; RESULT: 40824

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=9
;; GCA: 9. 31875000
;; Problem 9 (SOLVE:VERIFIED:POSTED)
;; 25 January 2002
;; 
;; A Pythagorean triplet is a set of three natural numbers, $a<b<c$, for which, $a^2 + b^2 = c^2$
;; 
;; For example, $32 + 42 = 9 + 16 = 25 = 52$.
;; 
;; There exists exactly one Pythagorean triplet for which $a+b+c=1000$.  Find the product $abc$.
;; 

(loop for a from 1 upto 998
      append (loop for b from a upto 998
                   for c = (- 1000 a b)
                   when (zerop (- (* c c) (* a a) (* b b)))
                   collect (* a b c)))
;; RESULT: (31875000)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=10
;; GCA: 10. 142913828922
;; Problem 10 (SOLVED:VERIFIED:POSTED)
;; 08 February 2002
;; 
;; The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
;; 
;; Find the sum of all the primes below two million.

(loop for i from 0
      for p = (mjr_prime_nth-small-prime i)
      while (< p 2000000)
      sum p)
;; RESULT: 142913828922

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=11
;; GCA: 11. 70600674
;; Problem 11 (SOLVED:VERIFIED:POSTED)
;; 22 February 2002
;; 
;; In the 20x20 grid below, four numbers along a diagonal line have been marked in red.
;; 
;; 08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
;; 49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
;; 81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65
;; 52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91
;; 22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80
;; 24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50
;; 32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70
;; 67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21
;; 24 55 58 05 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72
;; 21 36 23 09 75 00 76 44 20 45 35 14 00 61 33 97 34 31 33 95
;; 78 17 53 28 22 75 31 67 15 94 03 80 04 62 16 14 09 53 56 92
;; 16 39 05 42 96 35 31 47 55 58 88 24 00 17 54 24 36 29 85 57
;; 86 56 00 48 35 71 89 07 05 44 44 37 44 60 21 58 51 54 17 58
;; 19 80 81 68 05 94 47 69 28 73 92 13 86 52 17 77 04 89 55 40
;; 04 52 08 83 97 35 99 16 07 97 57 32 16 26 26 79 33 27 98 66
;; 88 36 68 87 57 62 20 72 03 46 33 67 46 55 12 32 63 93 53 69
;; 04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36
;; 20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16
;; 20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54
;; 01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48
;; 
;; The product of these numbers is 26 x 63 x 78 x 14 = 1788696.
;; 
;; What is the greatest product of four adjacent numbers in any direction (up, down, left, right, or diagonally) in the 20x20 grid?

(loop with ar = (make-array '(20 20) :initial-contents '((08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08)
                                                         (49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00)
                                                         (81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65)
                                                         (52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91)
                                                         (22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80)
                                                         (24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50)
                                                         (32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70)
                                                         (67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21)
                                                         (24 55 58 05 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72)
                                                         (21 36 23 09 75 00 76 44 20 45 35 14 00 61 33 97 34 31 33 95)
                                                         (78 17 53 28 22 75 31 67 15 94 03 80 04 62 16 14 09 53 56 92)
                                                         (16 39 05 42 96 35 31 47 55 58 88 24 00 17 54 24 36 29 85 57)
                                                         (86 56 00 48 35 71 89 07 05 44 44 37 44 60 21 58 51 54 17 58)
                                                         (19 80 81 68 05 94 47 69 28 73 92 13 86 52 17 77 04 89 55 40)
                                                         (04 52 08 83 97 35 99 16 07 97 57 32 16 26 26 79 33 27 98 66)
                                                         (88 36 68 87 57 62 20 72 03 46 33 67 46 55 12 32 63 93 53 69)
                                                         (04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36)
                                                         (20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16)
                                                         (20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54)
                                                         (01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48)))
      for xi below 20
      maximize (loop for yi below 20
                     maximize (loop for (xo . yo) in '((#(1 2 3 4) . #( 0  0  0  0))
                                                       (#(0 0 0 0) . #( 1  2  3  4))
                                                       (#(1 2 3 4) . #( 1  2  3  4))
                                                       (#(1 2 3 4) . #(-1 -2 -3 -4)))
                                    for prod = (reduce #'* (map 'list (lambda (xoi yoi)
                                                                        (let ((idx (list (+ xi xoi) (+ yi yoi))))
                                                                          (if (apply #'array-in-bounds-p ar idx)
                                                                              (apply #'aref ar idx)
                                                                              0)))
                                                                xo yo))
                                    maximize prod)))
;; RESULT: 70600674

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=12
;; GCA: 12. 76576500
;; Problem 12 (SOLVED:VERIFIED:POSTED)
;; 08 March 2002
;; 
;; The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 
;; $1 + 2 + 3 + 4 + 5 + 6 + 7 = 28$. The first ten terms would be:
;; 
;; $1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...$
;; 
;; Let us list the factors of the first seven triangle numbers:
;; 
;;      1: 1
;;      3: 1,3
;;      6: 1,2,3,6
;;     10: 1,2,5,10
;;     15: 1,3,5,15
;;     21: 1,3,7,21
;;     28: 1,2,4,7,14,28
;; 
;; We can see that 28 is the first triangle number to have over five divisors.
;; 
;; What is the value of the first triangle number to have over five hundred divisors?

(loop for n from 1
      for tn = n then (+ n tn)
      for fac = (mjr_prime_all-factors tn)
      when (> (length fac) 500)
      do (return tn))
;; RESULT: 76576500

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=13
;; GCA: 13. 5537376230
;; Problem 13 (SOLVED:VERIFIED:POSTED)
;; 22 March 2002
;; 
;; Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.
;; 37107287533902102798797998220837590246510135740250
;; 46376937677490009712648124896970078050417018260538
;; [..SNIP..]

(subseq (format nil "~d" (+ 37107287533902102798797998220837590246510135740250
                            46376937677490009712648124896970078050417018260538
                            74324986199524741059474233309513058123726617309629
                            91942213363574161572522430563301811072406154908250
                            23067588207539346171171980310421047513778063246676
                            89261670696623633820136378418383684178734361726757
                            28112879812849979408065481931592621691275889832738
                            44274228917432520321923589422876796487670272189318
                            47451445736001306439091167216856844588711603153276
                            70386486105843025439939619828917593665686757934951
                            62176457141856560629502157223196586755079324193331
                            64906352462741904929101432445813822663347944758178
                            92575867718337217661963751590579239728245598838407
                            58203565325359399008402633568948830189458628227828
                            80181199384826282014278194139940567587151170094390
                            35398664372827112653829987240784473053190104293586
                            86515506006295864861532075273371959191420517255829
                            71693888707715466499115593487603532921714970056938
                            54370070576826684624621495650076471787294438377604
                            53282654108756828443191190634694037855217779295145
                            36123272525000296071075082563815656710885258350721
                            45876576172410976447339110607218265236877223636045
                            17423706905851860660448207621209813287860733969412
                            81142660418086830619328460811191061556940512689692
                            51934325451728388641918047049293215058642563049483
                            62467221648435076201727918039944693004732956340691
                            15732444386908125794514089057706229429197107928209
                            55037687525678773091862540744969844508330393682126
                            18336384825330154686196124348767681297534375946515
                            80386287592878490201521685554828717201219257766954
                            78182833757993103614740356856449095527097864797581
                            16726320100436897842553539920931837441497806860984
                            48403098129077791799088218795327364475675590848030
                            87086987551392711854517078544161852424320693150332
                            59959406895756536782107074926966537676326235447210
                            69793950679652694742597709739166693763042633987085
                            41052684708299085211399427365734116182760315001271
                            65378607361501080857009149939512557028198746004375
                            35829035317434717326932123578154982629742552737307
                            94953759765105305946966067683156574377167401875275
                            88902802571733229619176668713819931811048770190271
                            25267680276078003013678680992525463401061632866526
                            36270218540497705585629946580636237993140746255962
                            24074486908231174977792365466257246923322810917141
                            91430288197103288597806669760892938638285025333403
                            34413065578016127815921815005561868836468420090470
                            23053081172816430487623791969842487255036638784583
                            11487696932154902810424020138335124462181441773470
                            63783299490636259666498587618221225225512486764533
                            67720186971698544312419572409913959008952310058822
                            95548255300263520781532296796249481641953868218774
                            76085327132285723110424803456124867697064507995236
                            37774242535411291684276865538926205024910326572967
                            23701913275725675285653248258265463092207058596522
                            29798860272258331913126375147341994889534765745501
                            18495701454879288984856827726077713721403798879715
                            38298203783031473527721580348144513491373226651381
                            34829543829199918180278916522431027392251122869539
                            40957953066405232632538044100059654939159879593635
                            29746152185502371307642255121183693803580388584903
                            41698116222072977186158236678424689157993532961922
                            62467957194401269043877107275048102390895523597457
                            23189706772547915061505504953922979530901129967519
                            86188088225875314529584099251203829009407770775672
                            11306739708304724483816533873502340845647058077308
                            82959174767140363198008187129011875491310547126581
                            97623331044818386269515456334926366572897563400500
                            42846280183517070527831839425882145521227251250327
                            55121603546981200581762165212827652751691296897789
                            32238195734329339946437501907836945765883352399886
                            75506164965184775180738168837861091527357929701337
                            62177842752192623401942399639168044983993173312731
                            32924185707147349566916674687634660915035914677504
                            99518671430235219628894890102423325116913619626622
                            73267460800591547471830798392868535206946944540724
                            76841822524674417161514036427982273348055556214818
                            97142617910342598647204516893989422179826088076852
                            87783646182799346313767754307809363333018982642090
                            10848802521674670883215120185883543223812876952786
                            71329612474782464538636993009049310363619763878039
                            62184073572399794223406235393808339651327408011116
                            66627891981488087797941876876144230030984490851411
                            60661826293682836764744779239180335110989069790714
                            85786944089552990653640447425576083659976645795096
                            66024396409905389607120198219976047599490197230297
                            64913982680032973156037120041377903785566085089252
                            16730939319872750275468906903707539413042652315011
                            94809377245048795150954100921645863754710598436791
                            78639167021187492431995700641917969777599028300699
                            15368713711936614952811305876380278410754449733078
                            40789923115535562561142322423255033685442488917353
                            44889911501440648020369068063960672322193204149535
                            41503128880339536053299340368006977710650566631954
                            81234880673210146739058568557934581403627822703280
                            82616570773948327592232845941706525094512325230608
                            22918802058777319719839450180888072429661980811197
                            77158542502016545090413245809786882778948721859617
                            72107838435069186155435662884062257473692284509516
                            20849603980134001723930671666823555245252804609722
                            53503534226472524250874054075591789781264330331690))
        0 10)
;; RESULT: "5537376230"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=14
;; GCA: 14. 837799
;; Problem 14 (SOLVED:VERIFIED:POSTED)
;; 05 April 2002
;; 
;; The following iterative sequence is defined for the set of positive integers:
;; 
;; $$n \rightarrow n/2 (n \mathrm{is even})$$
;; $$n \rightarrow 3n + 1 (n \mathrm{is odd})$$
;; 
;; Using the rule above and starting with 13, we generate the following sequence: 13, 40, 20, 10, 5, 16, 8, 4, 2, 1
;; 
;; It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is
;; thought that all starting numbers finish at 1.
;; 
;; Which starting number, under one million, produces the longest chain?
;; 
;; NOTE: Once the chain starts the terms are allowed to go above one million.

(loop with mln = 1
      with msv = 1
      for sv from 2 upto (1- 1000000)
      for seql = (loop for n = sv then (if (evenp n) (/ n 2) (1+ (* 3 n)))
                       count 't
                       until (= n 1))
      do (if (> seql mln)
             (setf mln seql
                   msv sv))
      finally (return (list msv mln)))
;; RESULT: (837799 525)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=16
;; GCA: 15. 137846528820
;; Problem 16 (SOLVED:VERIFIED:POSTED)
;; 19 April 2002
;;
;; Count ways across a 20x20 grid

(mjr_combe_comb (* 2 20) 20)
;; RESULT: 137846528820

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=16
;; GCA: 16. 1366
;; Problem 16 (SOLVED:VERIFIED:POSTED)
;; 03 May 2002
;; 
;; $2^15 = 32768$ and the sum of its digits is $3 + 2 + 7 + 6 + 8 = 26$.
;; 
;; What is the sum of the digits of the number $2^1000$?

(mjr_intu_sum-digits (expt 2 1000))
;; RESULT: 1366

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=17
;; GCA: 17. 21124
;; Problem 17
;; 17 May 2002
;; 
;; If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are $3+3+5+4+4=19$ letters used.
;; 
;; If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?
;; 
;; NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20
;; letters. The use of "and" when writing out numbers is in compliance with British usage.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=20
;; GCA: 20. 648
;; Problem 20 (SOLVED:VERIFIED:POSTED)
;; 21 June 2002
;; 
;; n! means n x (n - 1) x ... x 3 x 2 x 1
;; 
;; For example, 10! = 10 x 9 x ... x 3 x 2 x 1 = 3628800, and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.
;; 
;; Find the sum of the digits in the number 100!

(mjr_intu_sum-digits (mjr_combe_! 100))
;; RESULT: 648

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=21
;; GCA: 21. 31626
;; Problem 21 (UNSOLVED)
;; 05 July 2002
;; 
;; Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n).
;;
;; If $d(a) = b$ and $d(b) = a$, where $a \neq b$, then a and b are an amicable pair and each of a and b are called amicable numbers.
;;
;; For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; therefore d(220) = 284. The proper divisors of 284 are 1, 2, 4, 71
;; and 142; so d(284) = 220.
;; 
;; Evaluate the sum of all the amicable numbers under 10000.

(flet ((df (x) (- (reduce #'+ (mjr_prime_all-factors x)) x)))
  (loop for n from 2 upto (1- 10000)
        for dd = (df (df n))
        when (= n dd)
        sum (progn (format 't "~10d~%" n)
                   n)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=23
;; GCA: 23. 4179871
;; Problem 23 (SOLVED:VERIFIED:POSTED)
;; 02 August 2002
;; 
;; A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28
;; would be $1+2+4+7+14=28$, which means that 28 is a perfect number.
;; 
;; A number n is called deficient if the sum of its proper divisors is less than n and it is called abundant if this sum exceeds n.
;; 
;; As 12 is the smallest abundant number, $1+2+3+4+6=16$, the smallest number that can be written as the sum of two abundant numbers is 24. By mathematical
;; analysis, it can be shown that all integers greater than 28123 can be written as the sum of two abundant numbers. However, this upper limit cannot be
;; reduced any further by analysis even though it is known that the greatest number that cannot be expressed as the sum of two abundant numbers is less than
;; this limit.
;; 
;; Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers.

(let* ((abundant-list (loop for i from 1 upto 28123
                            when (mjr_prime_abundant? i)
                            collect i))
       (abundant-map (make-array (1+ 28123) :element-type 'bit  :initial-element 0)))
  (loop for j in abundant-list
        when (mjr_prime_abundant? j)
        do (setf (aref abundant-map j) 1))
  (loop for i from 1 upto 28123
        when (not (loop for j in abundant-list
                        until (>= j i)
                        when (= 1 (bit abundant-map (- i j)))
                        do (return 't)))
        sum i))
;; RESULT: 4179871

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=24
;; GCA: 24. 2783915460
;; Problem 24 (UNSOLVED)
;; 16 August 2002
;; 
;; A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations
;; are listed numerically or alphabetically, we call it lexicographic order. The lexicographic permutations of 0, 1 and 2 are:
;; 
;; 012   021   102   120   201   210
;; 
;; What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=25
;; GCA: 25. 4782
;; Problem 25 (SOLVED:VERIFIED:POSTED)
;; 30 August 2002
;; 
;; The Fibonacci sequence is defined by the recurrence relation:
;; 
;;     $F_n = F_{n-1} + F_{n-2}$ where $F_1 = 1$ and $F_2 = 1$.
;; 
;; Hence the first 12 terms will be:
;; 
;;     $$F_1 = 1    $$
;;     $$F_2 = 1    $$
;;     $$F_3 = 2    $$
;;     $$F_4 = 3    $$
;;     $$F_5 = 5    $$
;;     $$F_6 = 8    $$
;;     $$F_7 = 13   $$
;;     $$F_8 = 21   $$
;;     $$F_9 = 34   $$
;;     $$F_10 = 55  $$
;;     $$F_11 = 89  $$
;;     $$F_12 = 144 $$
;; 
;; The 12th term, F12, is the first term to contain three digits.
;; 
;; What is the first term in the Fibonacci sequence to contain 1000 digits?

(loop with (lst cur) = '(1 1)
      for i from 2
      when (>= (mjr_intu_count-digits cur) 1000)
      do (return i)
      do (psetf lst cur
                cur (+ lst cur)))
;; RESULT: 4782

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=29
;; GCA: 29. 9183
;; Problem 29 (SOLVED:VERIFIED:POSTED)
;; 25 October 2002
;; 
;; Consider all integer combinations of $a^b$ for $2 \le a \le 5$ and $2 \le b \le 5$:
;; 
;;     2^2=4,  2^3=8,   2^4=16,  2^5=32
;;     3^2=9,  3^3=27,  3^4=81,  3^5=243
;;     4^2=16, 4^3=64,  4^4=256, 4^5=1024
;;     5^2=25, 5^3=125, 5^4=625, 5^5=3125
;; 
;; If they are then placed in numerical order, with any repeats removed, we get the following sequence of 15 distinct terms:
;; 
;; $4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125$
;; 
;; How many distinct terms are in the sequence generated by ab for $2 \le a \le 100$ and $2 \le b \le 100$?

(length (remove-duplicates (sort (loop for a from 2 upto 100
                                       append (loop for b from 2 upto 100
                                                    collect (expt a b)))
                                 #'>)
                           :test #'=))
;; RESULT: 9183

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=34
;; GCA: 34. 40730 (SOLVED:VERIFIED:POSTED)
;; 
;; Problem 34
;; 03 January 2003
;; 
;; 145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
;; 
;; Find the sum of all numbers which are equal to the sum of the factorial of their digits.
;; 
;; Note: as 1! = 1 and 2! = 2 are not sums they are not included.

(loop for n from 3 
      for sdf = (reduce #'+ (mapcar #'mjr_combe_! (mjr_intu_convert-to-digit-list n)))
      when (= n sdf)
      sum (progn (format 't "~10d~%" n)
                 n))
;; RESULT: 40730

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=36
;; GCA: 36. 872187
;; 
;; Problem 36 (SOLVED:VERIFIED:POSTED)
;; 31 January 2003
;; 
;; The decimal number, 585 = 10010010012 (binary), is palindromic in both bases.
;; 
;; Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.
;; 
;; (Please note that the palindromic number, in either base, may not include leading zeros.)

(loop for n from 0 upto (1- 1000000)
      when (and (mjr_intu_same-palindromic? n 10)
                (mjr_intu_same-palindromic? n 2))
      sum n)
;; RESULT: 872187

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=35
;; GCA: 35. 55
;; Problem 35 (SOLVED:VERIFIED:POSTED)
;; 17 January 2003
;; 
;; The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.
;; 
;; There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.
;; 
;; How many circular primes are there below one million?

(loop for i from 0
      for p = (mjr_prime_nth-small-prime i)
      while (< p 1000000)
      count (not (loop with digits = (mjr_intu_convert-to-digit-list p)
                       with len = (length digits)
                       for i below (1- len)
                       do (setf digits (append (rest digits) (list (car digits))))
                       when (not (mjr_prime_primep (mjr_intu_convert-from-digit-list digits)))
                       do (return 't))))
;; RESULT: 55

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=46
;; GCA: 46. 5777
;; Problem 46 (SOLVED:VERIFIED:POSTED)
;; 20 June 2003
;; 
;; It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a square.
;; 
;;  9 =  7 + 2x1^2
;; 15 =  7 + 2x2^2
;; 21 =  3 + 2x3^2
;; 25 =  7 + 2x3^2
;; 27 = 19 + 2x2^2
;; 33 = 31 + 2x1^2
;; 
;; It turns out that the conjecture was false.
;; 
;; What is the smallest odd composite that cannot be written as the sum of a prime and twice a square?

(loop for i from 3 by 2
      when (not (or (mjr_prime_primep i)
                    (loop for j from 0
                          for p = (mjr_prime_nth-small-prime j)
                          for b = (truncate (realpart (sqrt (/ (- i p) 2))))
                          until (>= p i)
                          when (= i (+ p (* 2 b b)))
                          do (return 't))))
      do (return i))
;; RESULT: 5777

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=49
;; GCA: 48. 9110846700
;; Problem 48
;; 18 July 2003
;; 
;; The series, $1^1 + 2^2 + 3^3 + ... + 10^{10} = 10405071317$.
;; 
;; Find the last ten digits of the series, $1^1 + 2^2 + 3^3 + ... + 1000^{1000}$.

(second (multiple-value-list (truncate (loop for i from 1 upto 1000
                                             sum (expt i i))
                                       (expt 10 11))))
;; RESULT: 19110846700

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=49
;; GCA: 49. 296962999629
;; Problem 49 (SOLVED:VERIFIED:POSTED)
;; 01 August 2003
;; 
;; The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual in two ways: (i) each of the three terms are prime,
;; and, (ii) each of the 4-digit numbers are permutations of one another.
;; 
;; There are no arithmetic sequences made up of three 1-, 2-, or 3-digit primes, exhibiting this property, but there is one other 4-digit increasing sequence.
;; 
;; What 12-digit number do you form by concatenating the three terms in this sequence?

(loop for i1 from 168 upto 1228 ;; 4 digit primes
      for p1 = (mjr_prime_nth-small-prime i1)
      for p1s = (sort (format nil "~d" p1) #'char-greaterp)
      append (loop for i2 from (1+ i1) upto 1228
                   for p2 = (mjr_prime_nth-small-prime i2)
                   for p3 = (+ p2 (- p2 p1))
                   when (and (mjr_prime_primep p3)
                             (= 4 (mjr_intu_count-digits p3))
                             (equalp (sort (format nil "~d" p2) #'char-greaterp) p1s)
                             (equalp (sort (format nil "~d" p3) #'char-greaterp) p1s))
                   collect (format nil "~d~d~d" p1 p2 p3)))
;; RESULT: ("148748178147" "296962999629")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=50
;; GCA: 50. 997651
;; Problem 50 (UNSOLVED)
;; 15 August 2003
;; 
;; The prime 41, can be written as the sum of six consecutive primes: $41 = 2 + 3 + 5 + 7 + 11 + 13$
;; 
;; This is the longest sum of consecutive primes that adds to a prime below one-hundred.
;; 
;; The longest sum of consecutive primes below one-thousand that adds to a prime, contains 21 terms, and is equal to 953.
;; 
;; Which prime, below one-million, can be written as the sum of the most consecutive primes?

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=52
;; GCA: 52. 142857
;; Problem 52 (SOLVED:VERIFIED:POSTED)
;; 12 September 2003
;; 
;; It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order.
;; 
;; Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits.

(loop for i from 1 
      for is = (sort (format nil "~d" i) #'char-greaterp)
      when (not (loop for j from 2 upto 6
                      for ij = (* i j)
                      when (not (equalp is (sort (format nil "~d" ij) #'char-greaterp)))
                      do (return 't)))
      do (return i))
;; RESULT: 142857

;; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=53
;; GCA: 53. 4075
;; Problem 53 (SOLVED:VERIFIED:POSTED)
;; 26 September 2003
;; 
;; There are exactly ten ways of selecting three from five, 12345:
;; 
;; 123, 124, 125, 134, 135, 145, 234, 235, 245, and 345
;; 
;; In combinatorics, we use the notation, 5C3 = 10.
;; 
;; It is not until n = 23, that a value exceeds one-million: 23C10 = 1144066.
;; 
;; How many, not necessarily distinct, values of  nCr, for 1 <= n <= 100, are greater than one-million?

(loop for n from 1 upto 100
      sum (loop for r from 1 upto n
                count (> (mjr_combe_comb n r) 1000000)))
;; RESULT: 4075

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=55
;; GCA: 55. 249
;; Problem 55
;; 24 October 2003 (SOLVED:VERIFIED:POSTED)
;; 
;; If we take 47, reverse and add, 47 + 74 = 121, which is palindromic.
;; 
;; Not all numbers produce palindromes so quickly. For example,
;; 
;; 349 + 943 = 1292,
;; 1292 + 2921 = 4213
;; 4213 + 3124 = 7337
;; 
;; That is, 349 took three iterations to arrive at a palindrome.
;; 
;; Although no one has proved it yet, it is thought that some numbers, like 196, never produce a palindrome. A number that never forms a palindrome through
;; the reverse and add process is called a Lychrel number. Due to the theoretical nature of these numbers, and for the purpose of this problem, we shall
;; assume that a number is Lychrel until proven otherwise. In addition you are given that for every number below ten-thousand, it will either (i) become a
;; palindrome in less than fifty iterations, or, (ii) no one, with all the computing power that exists, has managed so far to map it to a palindrome. In fact,
;; 10677 is the first number to be shown to require over fifty iterations before producing a palindrome: 4668731596684224866951378664 (53 iterations,
;; 28-digits).
;; 
;; Surprisingly, there are palindromic numbers that are themselves Lychrel numbers; the first example is 4994.
;; 
;; How many Lychrel numbers are there below ten-thousand?
;; 
;; NOTE: Wording was modified slightly on 24 April 2007 to emphasise the theoretical nature of Lychrel numbers.

(loop for n from 0 upto 10000
      count (not (loop for i from 1 upto 50
                       for d = (mjr_intu_convert-to-digit-list n) then (mjr_intu_convert-to-digit-list p)
                       for p = (+ (mjr_intu_convert-from-digit-list d) (mjr_intu_convert-from-digit-list (reverse d)))
                       when (mjr_intu_palindromic? p)
                       do (return 't))))

;; RESULT: 249

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=56
;; GCA: 56. 972
;; Problem 56 (SOLVED:VERIFIED:POSTED)
;; 07 November 2003
;; 
;; A googol (10100) is a massive number: one followed by one-hundred zeros -- 100100 is almost unimaginably large: one followed by two-hundred zeros. Despite
;; their size, the sum of the digits in each number is only 1.
;; 
;; Considering natural numbers of the form, ab, where a, b < 100, what is the maximum digital sum?

(loop for a from 1 upto 100
      maximize (loop for b from 1 upto 100
                     maximize (mjr_intu_sum-digits (expt a b))))
;; RESULT: 972

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=60
;; GCA: 60. 26033
;; Problem 60 (SOLVED:VERIFIED:POSTED)
;; 02 January 2004
;; 
;; The primes 3, 7, 109, and 673, are quite remarkable. By taking any two primes and concatenating them in any order the result will always be prime. For
;; example, taking 7 and 109, both 7109 and 1097 are prime. The sum of these four primes, 792, represents the lowest sum for a set of four primes with this
;; property.
;; 
;; Find the lowest sum for a set of five primes for which any two primes concatenate to produce another prime.

(labels ((fnd-nxt (the-list max-p)
           (if (null the-list)
               (loop for i from 0 upto max-p
                     collect (list i))
               (loop for c in the-list
                     for cd = (mapcar (lambda (x) (mjr_intu_convert-to-digit-list (mjr_prime_nth-small-prime x))) c)
                     append (loop for i from (1+ (car (last c))) upto max-p
                                  for pd = (mjr_intu_convert-to-digit-list (mjr_prime_nth-small-prime i))
                                  when (not (loop for cpi in cd
                                                  when (or (not (mjr_prime_primep (mjr_intu_convert-from-digit-list (append cpi pd))))
                                                           (not (mjr_prime_primep (mjr_intu_convert-from-digit-list (append pd cpi)))))
                                                  do (return 't)))
                                  collect (append c (list i)))))))
  (let ((good-list nil))
    (dotimes (i 5)
      (setf good-list (fnd-nxt good-list 1200))
      (if (null good-list)
          (error "Could not find big enough set of primes~%")))
    (loop for c in good-list
          minimize (reduce #'+ (mapcar #'mjr_prime_nth-small-prime c)))))
;; RESULT: 26033

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=69
;; GCA: 69. 510510
;; Problem 69 (SOLVED:VERIFIED:POSTED)
;; 07 May 2004
;; 
;; Euler's Totient function, phi(n) is used to determine the number of numbers less than n which are relatively prime to n. For example, as 1, 2, 4, 5, 7, and
;; 8, are all less than nine and relatively prime to nine, phi(9)=6.
;;
;; n    Relatively Prime   phi(n)  n/phi(n)
;; 2    1                  1       2
;; 3    1,2                2       1.5
;; 4    1,3                2       2
;; 5    1,2,3,4            4       1.25
;; 6    1,5                2       3
;; 7    1,2,3,4,5,6        6       1.1666...
;; 8    1,3,5,7            4       2
;; 9    1,2,4,5,7,8        6       1.5
;; 10   1,3,7,9            4       2.5
;; 
;; It can be seen that n=6 produces a maximum n/phi(n) for n <= 10.
;; 
;; Find the value of $n \le 1000000$ for which n/phi(n) is a maximum.

(loop with maxv = 0
      with maxi = 0
      for i from 2 upto (expt 10 6)
      for v = (/ i (mjr_prime_phi-func i))
      when (> v maxv)
      do (print (setf maxv v
                      maxi i))
      finally (return maxi))
;; RESULT: 510510

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=70
;; GCA: 70. 8319823
;; Problem 70 (SOLVED:VERIFIED:POSTED)
;; 21 May 2004
;; 
;; Euler's Totient function, phi(n) [sometimes called the phi function], is used to determine the number of positive numbers less than or equal to n which are
;; relatively prime to n. For example, as 1, 2, 4, 5, 7, and 8, are all less than nine and relatively prime to nine, phi(9)=6.
;; 
;; The number 1 is considered to be relatively prime to every positive number, so phi(1)=1.
;; 
;; Interestingly, phi(87109)=79180, and it can be seen that 87109 is a permutation of 79180.
;; 
;; Find the value of n, 1 < n < 107, for which phi(n) is a permutation of n and the ratio n/phi(n) produces a minimum.

(loop with maxv = 0
      with maxi = 0
      for i from 2 upto (expt 10 7)
      for phi = (mjr_prime_phi-func i)
      for v = (/ i phi)
      when (and (> v maxv)
                (equalp (sort (format nil "~d" i)   #'char-greaterp)
                        (sort (format nil "~d" phi) #'char-greaterp)))
      do (print (setf maxv v
                      maxi i))
      finally (return maxi))
;; RESULT: 8319823

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=76
;; Problem 76
;; GCA: 76. 190569291 
;; 13 August 2004 (SOLVED:VERIFIED:POSTED)
;; 
;; It is possible to write five as a sum in exactly six different ways:
;; 
;; 4 + 1
;; 3 + 2
;; 3 + 1 + 1
;; 2 + 2 + 1
;; 2 + 1 + 1 + 1
;; 1 + 1 + 1 + 1 + 1
;; 
;; How many different ways can one hundred be written as a sum of at least two positive integers?

(1- (mjr_combe_partitions 100))
;; RESULT: 190569291 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=112
;; Problem 112
;; GCA: 112. 1587000
;; 30 December 2005 (SOLVED:VERIFIED:POSTED)
;; 
;; Working from left-to-right if no digit is exceeded by the digit to its left it is called an increasing number -- for example, 134468.
;; 
;; Similarly if no digit is exceeded by the digit to its right it is called a decreasing number -- for example, 66420.
;; 
;; We shall call a positive integer that is neither increasing nor decreasing a "bouncy" number -- for example, 155349.
;; 
;; Clearly there cannot be any bouncy numbers below one-hundred, but just over half of the numbers below one-thousand (525) are bouncy. In fact, the least
;; number for which the proportion of bouncy numbers first reaches 50% is 538.
;; 
;; Surprisingly, bouncy numbers become more and more common and by the time we reach 21780 the proportion of bouncy numbers is equal to 90%.
;; 
;; Find the least number for which the proportion of bouncy numbers is exactly 99%.


(loop for i from 1 
      for ip = (format nil "~d" i)
      for ips = (sort (format nil "~d" i) #'char-greaterp)
      count (or (equalp ip ips)
                (equalp ip (reverse ips))) into the-count
      when (= 1/100 (/ the-count i))
      do (return i))

;; RESULT: 1587000

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=179
;; GCA: 179. 986262
;; Problem 179
;; 26 January 2008
;; 
;; Find the number of integers $1 < n < 10^7$, for which n and n + 1 have the same number of positive divisors. For example, 14 has the positive divisors 1,
;; 2, 7, 14 while 15 has 1, 3, 5, 15.

;; Brute force solution (too slow)
(loop for d = 1 then nd
      for n from 2 upto (expt 10 7)
      for nd = (mjr_prime_num-factors n)
      count (= d nd))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://projecteuler.net/problem=203
;; Problem 203
;; GCA: 203. 34029210557338
;; 06 September 2008 (SOLVED:VERIFIED:POSTED)
;; 
;; The binomial coefficients nCk can be arranged in triangular form, Pascal's triangle, like this:
;; 	1	
;; 	1		1	
;; 	1		2		1	
;; 	1		3		3		1	
;; 	1		4		6		4		1	
;; 	1		5		10		10		5		1	
;; 	1		6		15		20		15		6		1	
;;  1		7		21		35		35		21		7		1
;; 
;; It can be seen that the first eight rows of Pascal's triangle contain twelve distinct numbers: 1, 2, 3, 4, 5, 6, 7, 10, 15,
;; 20, 21 and 35.
;; 
;; A positive integer n is called squarefree if no square of a prime divides n. Of the twelve distinct numbers in the first eight rows of Pascal's triangle,
;; all except 4 and 20 are squarefree. The sum of the distinct squarefree numbers in the first eight rows is 105.
;; 
;; Find the sum of the distinct squarefree numbers in the first 51 rows of Pascal's triangle.

(loop for c in (delete-duplicates (sort (loop for n from 0 upto 50
                                              append (loop for k from 0 upto n
                                                           collect (mjr_combe_comb n k)))
                                        #'>)
                                  :test #'=)
      when (mjr_prime_square-free? c)
      sum c)

;; RESULT: 34029210557338

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Project Euler solutions collected by Luckytoilet and others.
;; http://code.google.com/p/projecteuler-solutions/
;; http://eulersolutions.49.forumer.com/
;; 
;; GCA: 1. 233168
;; GCA: 2. 4613732
;; GCA: 3. 6857
;; GCA: 4. 906609
;; GCA: 5. 232792560
;; GCA: 6. 25164150
;; GCA: 7. 104743
;; GCA: 8. 40824
;; GCA: 9. 31875000
;; GCA: 10. 142913828922
;; GCA: 11. 70600674
;; GCA: 12. 76576500
;; GCA: 13. 5537376230
;; GCA: 14. 837799
;; GCA: 15. 137846528820
;; GCA: 16. 1366
;; GCA: 17. 21124
;; GCA: 18. 1074
;; GCA: 19. 171
;; GCA: 20. 648
;; GCA: 21. 31626
;; GCA: 22. 871198282
;; GCA: 23. 4179871
;; GCA: 24. 2783915460
;; GCA: 25. 4782
;; GCA: 26. 983
;; GCA: 27. -59231
;; GCA: 28. 669171001
;; GCA: 29. 9183
;; GCA: 30. 443839
;; GCA: 31. 73682
;; GCA: 32. 45228
;; GCA: 33. 100
;; GCA: 34. 40730
;; GCA: 35. 55
;; GCA: 36. 872187
;; GCA: 37. 748317
;; GCA: 38. 932718654
;; GCA: 39. 840
;; GCA: 40. 210
;; GCA: 41. 7652413
;; GCA: 42. 162
;; GCA: 43. 16695334890
;; GCA: 44. 5482660
;; GCA: 45. 1533776805
;; GCA: 46. 5777
;; GCA: 47. 134043
;; GCA: 48. 9110846700
;; GCA: 49. 296962999629
;; GCA: 50. 997651
;; GCA: 51. 121313
;; GCA: 52. 142857
;; GCA: 53. 4075
;; GCA: 54. 376
;; GCA: 55. 249
;; GCA: 56. 972
;; GCA: 57. 153
;; GCA: 58. 26241
;; GCA: 59. 107359
;; GCA: 60. 26033
;; GCA: 61. 28684
;; GCA: 62. 127035954683
;; GCA: 63. 49
;; GCA: 64. 1322
;; GCA: 65. 272
;; GCA: 66. 661
;; GCA: 67. 7273
;; GCA: 68. 6531031914842725
;; GCA: 69. 510510
;; GCA: 70. 8319823
;; GCA: 71. 428570
;; GCA: 72. 303963552391
;; GCA: 73. 7295372
;; GCA: 74. 402
;; GCA: 75. 161667
;; GCA: 76. 190569291 
;; GCA: 77. 71
;; GCA: 78. 55374
;; GCA: 79. 73162890
;; GCA: 80. 40886
;; GCA: 81. 427337
;; GCA: 82. 260324
;; GCA: 83. 425185
;; GCA: 84. 101524
;; GCA: 85. 2772
;; GCA: 86. 1818
;; GCA: 87. 1097343
;; GCA: 88. 7587457
;; GCA: 89. 743
;; GCA: 90. 1217
;; GCA: 91. 14234
;; GCA: 92. 8581146
;; GCA: 93. 1258
;; GCA: 94. 518408346
;; GCA: 95. 14316
;; GCA: 96. 24702
;; GCA: 97. 8739992577
;; GCA: 98. 18769
;; GCA: 99. 709
;; GCA: 100. 756872327473
;; GCA: 101. 37076114526
;; GCA: 102. 228
;; GCA: 103. 20313839404245
;; GCA: 104. 329468
;; GCA: 105. 73702
;; GCA: 106. 21384
;; GCA: 107. 259679
;; GCA: 108. 180180
;; GCA: 109. 38182
;; GCA: 110. 9350130049860600
;; GCA: 111. 612407567715
;; GCA: 112. 1587000
;; GCA: 113. 51161058134250
;; GCA: 114. 16475640049
;; GCA: 115. 168
;; GCA: 116. 20492570929
;; GCA: 117. 100808458960497
;; GCA: 118. 44680
;; GCA: 119. 248155780267521
;; GCA: 120. 333082500
;; GCA: 121. 2269
;; GCA: 122. 1582
;; GCA: 123. 21035
;; GCA: 124. 21417
;; GCA: 125. 2906969179
;; GCA: 126. 18522
;; GCA: 127. 18407904
;; GCA: 128. 14516824220
;; GCA: 129. 1000023
;; GCA: 130. 149253
;; GCA: 131. 173
;; GCA: 132. 843296
;; GCA: 133. 453647705
;; GCA: 134. 18613426663617118
;; GCA: 135. 4989
;; GCA: 136. 2544559
;; GCA: 137. 1120149658760
;; GCA: 138. 1118049290473932
;; GCA: 139. 10057761
;; GCA: 140. 5673835352990
;; GCA: 141. 878454337159
;; GCA: 142. 1006193
;; GCA: 143. 30758397
;; GCA: 144. 354
;; GCA: 145. 608720
;; GCA: 146. 676333270
;; GCA: 147. 846910284
;; GCA: 148. 2129970655314432
;; GCA: 149. 52852124
;; GCA: 150. -271248680
;; GCA: 151. 0.464399
;; GCA: 152. 301
;; GCA: 153. 17971254122360635
;; GCA: 154. 479742450
;; GCA: 155. 3857447
;; GCA: 156. 21295121502550
;; GCA: 157. 53490
;; GCA: 158. 409511334375
;; GCA: 159. 14489159
;; GCA: 160. 16576
;; GCA: 161. 20574308184277971
;; GCA: 162. 3D58725572C62302
;; GCA: 163. 343047
;; GCA: 164. 378158756814587
;; GCA: 165. 2868868
;; GCA: 166. 7130034
;; GCA: 167. 3916160068885
;; GCA: 168. 59206
;; GCA: 169. 178653872807
;; GCA: 170. 9857164023
;; GCA: 171. 142989277
;; GCA: 172. 227485267000992000
;; GCA: 173. 1572729
;; GCA: 174. 209566
;; GCA: 175. 1,13717420,8
;; GCA: 176. 96818198400000
;; GCA: 177. 129325
;; GCA: 178. 126461847755
;; GCA: 179. 986262
;; GCA: 180. 285196020571078987
;; GCA: 181. 83735848679360680
;; GCA: 182. 399788195976
;; GCA: 183. 48861552
;; GCA: 184. 1725323624056
;; GCA: 185. 4640261571849533
;; GCA: 186. 2325629
;; GCA: 187. 17427258
;; GCA: 188. 95962097
;; GCA: 189. 10834893628237824
;; GCA: 190. 371048281
;; GCA: 191. 1918080160
;; GCA: 192. 57060635927998347
;; GCA: 193. 684465067343069
;; GCA: 194. 61190912
;; GCA: 195. 75085391
;; GCA: 196. 322303240771079935
;; GCA: 197. 1.710637717
;; GCA: 198. 52374425
;; GCA: 199. 0.00396087
;; GCA: 200. 229161792008
;; GCA: 201. 115039000
;; GCA: 202. 1209002624
;; GCA: 203. 34029210557338
;; GCA: 204. 2944730
;; GCA: 205. 0.5731441
;; GCA: 206. 1389019170
;; GCA: 207. 44043947822
;; GCA: 208. 331951449665644800
;; GCA: 209. 15964587728784
;; GCA: 210. 1598174770174689458
;; GCA: 211. 1922364685
;; GCA: 212. 328968937309
;; GCA: 213. 330.721154
;; GCA: 214. 1677366278943
;; GCA: 215. 806844323190414
;; GCA: 216. 5437849
;; GCA: 217. 6273134
;; GCA: 218. 0
;; GCA: 219. 64564225042
;; GCA: 220. 139776,963904
;; GCA: 221. 1884161251122450
;; GCA: 222. 1590933
;; GCA: 223. 61614848
;; GCA: 224. 4137330
;; GCA: 225. 2009
;; GCA: 226. 0.11316017
;; GCA: 227. 3780.618622
;; GCA: 228. 86226
;; GCA: 229. 11325263
;; GCA: 230. 850481152593119296
;; GCA: 231. 7526965179680
;; GCA: 232. 0.83648556
;; GCA: 233. 271204031455541309
;; GCA: 234. 1259187438574927161
;; GCA: 235. 1.002322108633
;; GCA: 236. 123/59
;; GCA: 237. 15836928
;; GCA: 238. 9922545104535661
;; GCA: 239. 0.001887854841
;; GCA: 240. 7448717393364181966
;; GCA: 241. 482316491800641154
;; GCA: 242. 997104142249036713
;; GCA: 243. 892371480
;; GCA: 244. 96356848
;; GCA: 245. 288084712410001
;; GCA: 246. 810834388
;; GCA: 247. 782252
;; GCA: 248. 23507044290
;; GCA: 249. 9275262564250418
;; GCA: 250. 1425480602091519
;; GCA: 251. 18946051
;; GCA: 252. 104924.0
;; GCA: 253. 11.492847
;; GCA: 254. 8184523820510
;; GCA: 255. 4.4474011180
;; GCA: 256. 85765680
;; GCA: 257. 139012411
;; GCA: 258. 12747994
;; GCA: 259. 20101196798
;; GCA: 260. 167542057
;; GCA: 261. 238890850232021
;; GCA: 262. 2531.205
;; GCA: 263. 2039506520
;; GCA: 264. 2816417.1055
;; GCA: 265. 209110240768
;; GCA: 266. 1096883702440585
;; GCA: 267. 0.999992836187
;; GCA: 268. 785478606870985
;; GCA: 269. 1311109198529286
;; GCA: 270. 82282080
;; GCA: 271. 4617456485273129588
;; GCA: 272. 8495585919506151122
;; GCA: 273. 2032447591196869022
;; GCA: 274. 1601912348822
;; GCA: 275. 15030564
;; GCA: 276. 5777137137739632912
;; GCA: 277. 1125977393124310
;; GCA: 278. 1228215747273908452
;; GCA: 279. 416577688
;; GCA: 280. 430.088247
;; GCA: 281. 1485776387445623
;; GCA: 282. 1098988351
;; GCA: 283. 28038042525570324
;; GCA: 284. 5a411d7b
;; GCA: 285. 157055.80999
;; GCA: 286. 52.6494571953
;; GCA: 287. 313135496
;; GCA: 288. 605857431263981935
;; GCA: 289. 6567944538
;; GCA: 290. 20444710234716473
;; GCA: 291. 4037526
;; GCA: 292. 3600060866
;; GCA: 293. 2209
;; GCA: 294. 789184709
;; GCA: 295. 4884650818
;; GCA: 296. 1137208419
;; GCA: 297. 2252639041804718029
;; GCA: 298. 1.76882294
;; GCA: 299. 549936643
;; GCA: 300. 8.0540771484375
;; GCA: 301. 2178309
;; GCA: 302. 1170060
;; GCA: 303. 1111981904675169
;; GCA: 304. 283988410192
;; GCA: 305. 18174995535140
;; GCA: 306. 852938
;; GCA: 307. 0.7311720251

;; http://bentilly.blogspot.com/2010/01/solving-project-euler-problems.html