How to resolve the algorithm Curzon numbers step by step in the OCaml programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Curzon numbers step by step in the OCaml programming language
Table of Contents
Problem Statement
A Curzon number is defined to be a positive integer n for which 2n + 1 is evenly divisible by 2 × n + 1. Generalized Curzon numbers are those where the positive integer n, using a base integer k, satisfy the condition that kn + 1 is evenly divisible by k × n + 1. Base here does not imply the radix of the counting system; rather the integer the equation is based on. All calculations should be done in base 10. Generalized Curzon numbers only exist for even base integers.
and even though it is not specifically mentioned that they are Curzon numbers:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Curzon numbers step by step in the OCaml programming language
Source code in the ocaml programming language
let modpow m =
let rec loop p b e =
if e land 1 = 0
then if e = 0 then p else loop p (b * b mod m) (e lsr 1)
else loop (p * b mod m) (b * b mod m) (e lsr 1)
in loop 1
let is_curzon k n =
let r = k * n in r = modpow (succ r) k n
let () =
List.iter (fun x ->
Seq.(ints 0 |> filter (is_curzon x) |> take 50 |> map string_of_int)
|> List.of_seq |> String.concat " " |> Printf.printf "base %u:\n%s\n" x)
[2; 4; 6; 8; 10]
let () =
List.iter (fun x ->
Seq.(ints 0 |> filter (is_curzon x) |> drop 999 |> take 1
|> iter (Printf.printf "base %u (1000th): %u\n" x)))
[2; 4; 6; 8; 10]
You may also check:How to resolve the algorithm Sub-unit squares step by step in the Julia programming language
You may also check:How to resolve the algorithm Rock-paper-scissors step by step in the Ruby programming language
You may also check:How to resolve the algorithm Compound data type step by step in the J programming language
You may also check:How to resolve the algorithm Forward difference step by step in the SQL programming language
You may also check:How to resolve the algorithm Dragon curve step by step in the AmigaE programming language