diff options
| author | Omar Magdy <omar.professional8777@gmail.com> | 2022-04-30 01:13:40 +0200 |
|---|---|---|
| committer | Omar Magdy <omar.professional8777@gmail.com> | 2022-04-30 01:13:40 +0200 |
| commit | a0d7b8320a8996eee0ed957b79c3a882f8b47146 (patch) | |
| tree | 76242ae2b19bad00796ed6d0104da8a0e4a99abe /python/Kaprekar.py | |
| download | competitive-programming-a0d7b8320a8996eee0ed957b79c3a882f8b47146.tar.xz competitive-programming-a0d7b8320a8996eee0ed957b79c3a882f8b47146.zip | |
Added all current problems
Diffstat (limited to 'python/Kaprekar.py')
| -rwxr-xr-x | python/Kaprekar.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/python/Kaprekar.py b/python/Kaprekar.py new file mode 100755 index 0000000..199b1c2 --- /dev/null +++ b/python/Kaprekar.py @@ -0,0 +1,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) + + |
