aboutsummaryrefslogtreecommitdiff
path: root/python/Kaprekar.py
blob: 199b1c234307a05577c42462bc0469ce6bdead36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env python3
from math import ceil

p = int(input())
q = int(input())

def splitNum(n):
    sn = str(n)
    l = len(sn)
    d = int((l + 1) / 2)
    if l % 2 == 0:
        d = int(ceil(l / 2))
    if(len(sn[d:].lstrip('0')) != 0):
        return int(sn[0:l - d]) + int(sn[l-d:].lstrip('0'))

for i in range(p, q):
    if i == splitNum(i * i):
        print(i)