From 9e81971f252975f010c2461b2229761eb75f6e22 Mon Sep 17 00:00:00 2001 From: Landon Curt Noll Date: Wed, 6 Sep 2017 17:41:56 -0700 Subject: [PATCH] Verify that h*2^n-1 is not a multiple of 3 --- cal/lucas.cal | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cal/lucas.cal b/cal/lucas.cal index 8cce569..a7c2055 100644 --- a/cal/lucas.cal +++ b/cal/lucas.cal @@ -1041,7 +1041,8 @@ next_x = 129; * n n as in h*2^n-1 (must be >= 1) * * output: - * returns v(1), or -1 is there is no quick way + * returns v(1), or + * -1 when h*2^n-1 is a multiple of 3 */ define gen_v1(h, n) @@ -1068,6 +1069,14 @@ gen_v1(h, n) quit "bad args: n must be an integer >= 1"; } + /* + * pretest: Verify that h*2^n-1 is not a multiple of 3 + */ + if (((h % 3 == 1) && (n % 2 == 0)) || ((h % 3 == 2) && (n % 2 == 1))) { + /* no need to test h*2^n-1, it is not prime */ + return -1; + } + /* * check for Case 1: (h mod 3 != 0) */