1

I use pari most of the time for my computational number theory research. I entered the following: for(x=1,100,print1(eulerphi(n)-1))
which gives the values of φ(n)-1 for integers 1 to 100. Here φ(n) is the number of integers less than n which are relatively prime to n. It gave the following output:
0 0 1 1 3 1 5 3 5 3 ... 65 31 43 23 69 2 43 59 45 71 31 95 41 59 39
(I excluded some integers to make the question short) I want to check if a number is in those numbers. How can I do so?

1 Answers1

1

You can use function setsearch to perform binary search through sorted list. It returns the 1-based index of match or 0 if nothing is found. Your example is here:

xs = Set(vector(100, n, eulerphi(n)-1))
> [0, 1, 3, 5, 7, ..., 87, 95]

setsearch(xs, 4)
> 4

setsearch(xs, 20)
> 0
Piotr Semenov
  • 1,761
  • 16
  • 24
  • But how can I enter all the numbers that were given as output of the command? I cannot type so many numbers. –  Nov 24 '20 at 09:03
  • Just use `vector` for list comprehension. I've just updated the example in my answer post according to your concern. Hope, it helps :) – Piotr Semenov Nov 24 '20 at 09:11
  • setsearch requires the vector to be in sorted order, otherwise it may not find the value (it uses a binary search). You need to wrap the initial constructor of xs with Set(....) – Andrew Nov 24 '20 at 21:13