# Isolate integers in a pair from a table?

Posted 17 days ago
293 Views
|
4 Replies
|
4 Total Likes
|
 Evening,I am trying to isolate the whole numbers/integers from a pair of numbers within a range. This is the function I am currently using: Table[{Sqrt[1 + 5 k^2], Sqrt[k^2]}, {k, 0, 500}] I want to find out which of the Sqrt(1+5k^2) is a square number itself, so a whole number. I am currently having to try a range and read through all my results. What I would like to to use a command, or a different command to the above, to just show those results that give me whole numbers. I hope I have explained that well enough and am asking in the right place. Thank you in advance.
4 Replies
Sort By:
Posted 17 days ago
 Hi Emily,Is this what you mean? Table[{Sqrt[1 + 5 k^2], Sqrt[k^2]}, {k, 0, 500}] // Select[IntegerQ@First@# &] (* {{1, 0}, {9, 4}, {161, 72}} *) 
Posted 17 days ago
 Yes!! Yes that is exactly it thank you! I was scouring Google for hours earlier today. Thank you so much!
Posted 16 days ago
 There is usually more than one way to solve problems, this is another. Cases[Table[{Sqrt[1 + 5 k^2], Sqrt[k^2]}, {k, 0, 500}], {a_, b_} /; IntegerQ[a]] 
Posted 16 days ago
 Another variant: Cases[Table[{Sqrt[1 + 5 k^2], Sqrt[k^2]}, {k, 0, 500}], {_Integer, _}] 
Community posts can be styled and formatted using the Markdown syntax.