3
$\begingroup$

Let $F_n$ denote the $n$-th Fibonacci number. I am interested in the sequence $$a(k, n)=\left | \left \{0 \leq m \leq n: \frac{F_m}{k} \; \text{is a perfect square} \right \} \right |,$$ where $|\cdot|$ denotes the cardinality of a set.

For example, $a(1, 100) = 4$ since there are only four perfect squares among the first $n=100$ Fibonnaci numbers: $F_0=0$, $F_1=1$, $F_2=1$ and $F_{12}=144$.

How can I write a code to calculate $a(k, n)$?

$\endgroup$
3
  • $\begingroup$ What is perfect square? $\endgroup$
    – cvgmt
    Jun 24, 2023 at 11:17
  • 2
    $\begingroup$ @cvgmt, I think this is a common synonym for a square number. $\endgroup$
    – Domen
    Jun 24, 2023 at 11:45
  • $\begingroup$ @Domen I know Perfect triangle numbers etc. but I do not know Perfect square. $\endgroup$
    – cvgmt
    Jun 25, 2023 at 0:14

1 Answer 1

4
$\begingroup$

You did not give an example. Is this what you want?

Using Michael E2 code to check for perfect square from Fastest square number test

ClearAll[a,sQ];
sQ[n_]:=FractionalPart@Sqrt[n+0``1]==0;
a[k_Integer,n_Integer?Positive]:=Table[f=Fibonacci[m]/k; If[sQ[f],m,Nothing],{m,0,n}];
a[1,100]

Mathematica graphics

Length[%]
(*4*)
$\endgroup$
8
  • $\begingroup$ I am sorry for the misunderstanding. The horizontal brackets denote cardinality. $\endgroup$
    – user227351
    Jun 24, 2023 at 10:17
  • $\begingroup$ $a(n,k)$ is essentially the number of integers $m$ less than $n$ such that $F_m/k$ is a perfect square. $\endgroup$
    – user227351
    Jun 24, 2023 at 10:17
  • $\begingroup$ @user227351 Ok, if all what you want is the number of integers $m$ that satisfy this, then simply it will be the length of the result. No? Will update. $\endgroup$
    – Nasser
    Jun 24, 2023 at 10:23
  • $\begingroup$ I am not that competent, but SquareFreeQ ask "Is $n$ square free?" not "Is $n$ not a square?". $\endgroup$
    – user227351
    Jun 24, 2023 at 10:25
  • 1
    $\begingroup$ @user227351 could you check if this is now what you meant? Found a test for perfect square. So in this example, the length is 3. $\endgroup$
    – Nasser
    Jun 24, 2023 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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