A computer science problem by Paola Ramírez

How many 4-digit perfect squares A B C D \overline{ABCD} are there such that A B C D \overline{AB}-\overline{CD} is also a perfect square?


The answer is 11.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Mehdi K.
May 26, 2016
1
sum(1 for ele in [i ** 2 for i in range(34, 100)] if ele // 100 - (ele % 100) in [i ** 2 for i in range(10)])

Christopher Boo
May 21, 2016

Brute force solution by searching every 4 digit number and mark those that satisfies the property.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
import math

def perfect(x):
    return math.floor(math.sqrt(x)) * math.floor(math.sqrt(x)) == x

ans = 0

for x in range(1000,10000):
    y = x / 100 - x % 100
    if perfect(x) and y >= 0 and perfect(y):
        ans += 1

print ans

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...