Perfect square is an element of algebraic structure which is equal to the square (algebra) of another element.
Questions tagged [perfect-square]
87 questions
1
vote
3 answers
How to write a recursive function that returns a list made up of squares of the elements of lst?
Im not sure how to get my recursion to work properly or keep from infinitely repeating.
This is what i have so far:
def listSquareR(lst):
if len(lst)== 1:
return lst[0]**2
else:
return lst[0]**2+[listSquareR(lst[1:])]
last…

user3490784
- 21
- 1
- 4
1
vote
3 answers
How do I square a number without using multiplication?
Was wondering if there is a way to write a method which squares a number (integer or decimal/float) without using the operational sign (*). For example: square of 2 will be 4, square of 2.5 will be 6.25, and 3.5's will be 12.25.
Here is my…

Surya
- 15,703
- 3
- 51
- 74
1
vote
1 answer
Prolog Program to Find Square of Natural Numbers
My code below is meant to generate the square of natural numbers in order
(i.e sq(X). -> X=0; X=1; X=4; X=9; X=16; ...)
nat(0).
nat(X) :- nat(Y), Z is Y+1, X is Z*Z.
but the answer I am getting is:
1
0 ?- nat(X).
X = 0 ;
X = 1 ;
X = 4 ;
X =…

Kevin Cruz
- 37
- 5
0
votes
1 answer
How to factor out perfect squares from under the square root sign?
I am trying to calculate the square root, and keep the part which could not change into integer in C++, and I found This post on Stack Overflow, but it will still have decimal.
For example, if I want to calculate √8, I want the result to be 2√2 but…

Han Han
- 328
- 12
0
votes
0 answers
Why isn't this perfect square finder working for some numbers?
public static boolean isSquare(int n) {
if (n < 0) {
return false;
}
if (n == 0) {
return true;
}
for (int i = 0; i <= n; i++) {
if (i * i == n) { //checks if no. is perfect square//
return true;
}
}
return false;
}
why…

Elachi
- 3
- 1
- 3
0
votes
1 answer
Prolog algorithm works for 4x4 but not for higher dimensions
This is a follow-up Question of: Restrict search in Prolog - Magic Sqare
Thanks to Isabelle Newbie for the help so far.
With the help of Isabelle Newbie I got my code working, but sadly only for 4x4 Squares.
I'm quite new to Prolog, so maybe I miss…

LeMäx
- 23
- 4
0
votes
1 answer
Fastest function to find largest perfect squares of a single number?
I'm attempting to write an algorithm that will find the largest perfect squares of a given integer, subtracting their values from the total each time, as fast as possible. It's somewhat hard to explain, and I apologize for the somewhat ambiguous…

Will Berner
- 9
- 2
0
votes
1 answer
How do you accept multiple inputs and check whether it is a perfect square or not in Python without math?
lst=[]
n=int(input())
for i in range(0,n):
ele=int(input("Enter: "))
lst.append(ele)
for i in range(ele+1):
power = i * i
if power == ele:
print("perfect sq")
elif power > ele:
print("not a perf sq")
I've tried a few things but…

Kiran Vishwak
- 43
- 5
0
votes
2 answers
perfect squares leetcode - recursive solution with memoization
Trying to solve this problem with recursion and memoization but for input 7168 I'm getting wrong answer.
public int numSquares(int n) {
Map memo = new HashMap();
List list = fillSquares(n, memo);
…

maxam
- 159
- 1
- 9
0
votes
0 answers
Expanding stack with list comprehensions
How to explain that list comperhensions expression does not work (python 3.8.2 32bit env):
def perfect_squares(max_psqare):
psqares = [0]
return [psqares.append(psqares[-1] + 2 * i - 1) for i in range(1, int(max_psqare ** 0.5) + 1)]
in…

lissajous
- 371
- 5
- 17
0
votes
1 answer
Modify a given pseudocode such that it contains no loops
Consider the pseudocode:
read n (non-zero natural number)
x <- 1
y <- n
d <- 2
while x < y
{
if n % d = 0
{
x <- d
y <- [n / d]
}
d <- d + 1
}
if x = y
{
write 'D', x
}
else
{
write 'N'
}
I have to…

user010517720
- 2,127
- 2
- 7
- 15
0
votes
3 answers
How do I find perfect square from a set of numbers in Java?
So I'm trying to find out the perfect squares within a set of numbers. I declared the necessary variables, added a for loop, added a sqroot = Math.sqrt(num) and a print method to list the numbers. What I can't figure out is how can I make the…

Anonymous
- 17
- 1
- 5
0
votes
1 answer
(C++) Generate first p*n perfect square numbers in an array (p and n inputted from the keyboard)
I input p and n (int type) numbers from my keyboard, I want to generate the first p*n square numbers into the array pp[99]. Here's my code:
#include
#include
using namespace std;
int main()
{
int i, j, n, p,…

Lastrevio
- 41
- 1
- 7
0
votes
2 answers
Sum of all possible distinct perfect squares equals to square of given number
I am trying to write a program to solve a problem which states as follows
"Print all possible distinct perfect squares whose sum is equal to the square of given number".
For example -
Input
11
Output
1 4 16 36 64
1 4 16 100
4 36 81
I tried basic…

Anakar
- 112
- 11
0
votes
1 answer
How to create loop that runs through Square Pyramidal equation
Pretty new to Java. I'm trying to create code that finds out which square pyramidal number is itself a perfect square.
The square pyramidal number basically refers to the total number of balls in a pyramid that has a layer number of n. I'm looking…

kr3000
- 3
- 2