Questions tagged [perfect-square]

Perfect square is an element of algebraic structure which is equal to the square (algebra) of another element.

87 questions
1
vote
1 answer

Function to check for perfect square not working for large number

I came across an algorithm to tell if a given number is perfect square or not in O(logN) time. Here is the implementation(JAVA) of the idea. public boolean isPerfectSquare(long x) { if (x <= 1) return true; long…
Piyush Keshari
  • 170
  • 2
  • 10
1
vote
1 answer

Getting Multiple Inputs and checking if they are Perfect squares or not without using math

def isPerfectSquare(n) : i = 1 while(i * i<= n): if ((n % i == 0) and (n / i == i)): return True i = i + 1 return False lst=[] n=int(input()) for i in range(0,n): ele=int(input("Enter: ")) …
1
vote
1 answer

Finding the number of even perfect square proper divisors of a given number N

I tried to solve a question on HackerRank (Problem Link: https://www.hackerrank.com/challenges/mehta-and-his-laziness/problem) which involves calculating the number of even perfect square proper divisors of a given number N. The problem requires the…
1
vote
1 answer

Efficiently computing all the perfect square numbers for very large numbers like 10**20

Examples of perfect square numbers are 1,4,9,16,25.... How do we compute all the perfect square numbers for very large numbers like 10 pow 20. For 10 pow 20 there are 10 pow 10 perfect square numbers. So far what i have done.... Bruteforce : …
prolific
  • 13
  • 7
1
vote
2 answers

Recursively finding a sum of perfect squares in a list

I'm trying to recursively find a sum of perfect squares in a dynamically allocated list. For some reason, my function keeps overlooking the first element. *A is the pointer to the first element of the array. n is the number of elements, meaning…
randomuser
  • 299
  • 1
  • 4
  • 11
1
vote
1 answer

Recursive Newton Square Root Function Only Terminates for Perfect Squares

I wrote a program that looks very similar to other recursive newton square root functions I have seen on the web. For some reason this one only works with perfect squares and I can't seem to find a reason why. I have tried passing 3…
1
vote
2 answers

java program that finds all palindrome perfect squares between two integers supplied as input

I need to write a program that finds all the palindrome perfect squares between two integers supplied as an input but that do not include the inputs supplied. My program gets "killed" when you put in a large range of inputs i.e 10000 and 100000.…
Steph
  • 13
  • 4
1
vote
2 answers

Prime number and Perfect Square Checker in Python

I am trying to write my own prime number and perfect square checker using Python, The function should print 'Foo' if this is a prime number, print 'Bar' if this is a perfect square, print 'FooBar' if it is neither here is my code: def FooBar(): …
Edward Sun
  • 183
  • 2
  • 12
1
vote
1 answer

Squares from Integer Variables in C

How do you make squares from integer variables? Here is my code: #include int main(){ int n, p1, p2, p3, p4; printf("Enter 4 numbers:") scanf("%d %d %d %d", &n, &p1, &p2, &p3); printf("%d %d %d %d\n", n, p1, p2, p3); …
user5167255
1
vote
4 answers

Finding if n! + 1 is a perfect square

I'm trying to write a program to look for a number, n, between 0 and 100 such that n! + 1 is a perfect square. I'm trying to do this because I know there are only three so it was meant as a test of my Python ability. Refer to Brocard's problem.
PythonNewbie
  • 43
  • 1
  • 4
1
vote
4 answers

Square using define directive not working

I implemented a squaring define directive as this : #include #define SQR(y) ((y)*(y)) int main() { int a; printf("Enter : "); scanf("%d",&a); a = SQR(a); printf("The square is: %d\n",SQR(a)); return 0; } But when…
1
vote
1 answer

For each member of a sequence, determine if it is a perfect square

What I'm asking about is not a duplicate of this very popular question. For a randomly chosen input, some quick tests can be done and if they fail to say "not a square", some computation of the square root has to be done (I myself tried a solution,…
maaartinus
  • 44,714
  • 32
  • 161
  • 320
1
vote
4 answers

python 'int' object has no attribute 'sort'

Hey I am new to Python and I have this exercise I want to complete but I get the following error: 'int' object has no attribute 'sort'. I must use for-loop to take from a list of numbers and make them all square, then print them all out one by one…
Liblikas
  • 37
  • 1
  • 1
  • 4
1
vote
1 answer

Numpy failing to properly square array

I'm trying to map a simple quadratic function, where zs is a numpy array and R is a constant Ns = -np.square(zs) + 2*zs*R+ 3*R**2 It works fine most of the time, but for some reason whenever I have the evaluation set up as following the code…
1
vote
1 answer

c function, that get a matrix, then squaring it

My target is a to write a c function, that reads a number n and the elements (type:double) of the n*n matrix, then i get back the result of multiplying the matrix by itself. Example: input: 3 1.0 0.0 0.0 1.0 1.0 1.0 0.0 0.0 1.0 output: 1.0 0.0…
Mathiassa
  • 27
  • 9