Let $x=\frac{p}{q}$, where $p,q \in \mathbb{N}$.

Graph the function;

$$f(x)=\left\{\begin{matrix} \frac{\min(p,q)+1}{\max(p,q)+1} & \text{if }\text{GCD}(p,q)=1 \\ & \\ 0 & \text{if }\text{GCD}(p,q)\neq1 \end{matrix}\right.$$

Graphing the function by hand is quite easy to understand, and quite difficult to plot. Unfortunately I do not know any graphing website or software where we can define a function as mentioned. Any help will be appreciated.


I think it is really difficult to plot this function, since it is a very particular and unusual case. However, I have a tip for you. You can generate your own script for plotting it using programming methods. Bellow is an idea of how to build your algorithm.

  • define $p=1$ and $q=1$

  • from $i=1$ to $N_1$ do

  • from $j=1$ to $N_2$ do

  • $p=p+1$

  • $q=q+1$

  • define $F=\dfrac{\text{min}(p,q)+1}{\text{max}(p,q)+1}$

  • find common divisors of p and q (this requires a factorization algorithm)

  • put their common divisors in decreasing order
  • if the highest common divisor is one, write in the external file $\left(\dfrac{p}{q}, F\right)$
  • else, write in the external file $\left(\dfrac{p}{q}, 0\right)$

You can choose the $N_1$ and $N_2$ values, but remember the bigger $N_1$ and $N_2$ the higher your program will take to factorize p and q. After that, you can use any simple program to plot your external file.

  • 1
    $\begingroup$ If you want to add a pseudocode, the identation will help a lot (like python). So try to make 4 spaces in every new line for identation $\endgroup$ – Luis Felipe Aug 8 at 14:12
  • $\begingroup$ @LuisFelipe thank you so much. I am a new user here, still learning. Your comment will be of great help for me. $\endgroup$ – Eduardo Henrique Aug 8 at 14:13
  • $\begingroup$ also, you can select a section and press ALT+K $\endgroup$ – Luis Felipe Aug 8 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.