Problem returning a value

I want the code to: return the smallest prime divisor of a number N (Which is D)

But what I’m getting is: not the expected

My code looks like this:

% your code here
fn(N,D) :- \+(isPrime(N)),
	         N>=4.
                 /*Here I should find D which is the latest value of C at hlpUp(N,2)
               but I cant find a way to connect them.Also N is composite.Im new to prolog so I need some tips.*/
hlpUp(N,C) :- isPrime(C), N mod C =:= 0.
hlpUp(N,C) :- N > C+1, hlpUp(N,C+1).                  

Blockquote
I want the code to: return the smallest prime divisor of a number N (Which is D)

Let’s think about what that means from first principles.
Prime number: A positive integer that is greater than 1 and can be divided only by 1 and itself.

Factor: A number that can divide into another number with no remainder.

From these definitions, it would seem that we need at least 2 predicates:

  1. To generate a list of factors for an arbitrary number N.
  2. A predicate to test if a number is prime.

Predicate 2 is closely related to 1, which suggests collecting the results in a list, and using recursion to process them.

Big hint: if we input a prime number to a predicate that generates a factor list, how long should it be, if we omit 1 as a factor?

1 Like