-
Notifications
You must be signed in to change notification settings - Fork 1k
/
automorphic_number.jl
48 lines (33 loc) · 1021 Bytes
/
automorphic_number.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""Julia program to check if a number is automorphic or not.
An Automorphic Number is such a number whose square ends in the same digits as the number itself."""
function check_automophic(num)
temp = num * num
while(num > 0)
# Extract the last digits of the given number and its square.
lastNum = num % 10
lastSquare = temp % 10
# Check if they are equal
if(lastNum != lastSquare)
return "The given number $n is not an Automorphic Number."
end
num = num ÷ 10
temp = temp ÷ 10
end
return "The given number $n is an Automorphic Number."
end
print("Enter the number: ")
n = readline()
n = parse(Int, n)
res = check_automophic(abs(n))
print(res)
"""
Time Complexity: O(log(n)), where 'n' is the given number
Space Complexity: O(1)
SAMPLE INPUT AND OUTPUT
SAMPLE 1
Enter the number: 24
The given number 24 is not an Automorphic Number.
SAMPLE 2
Enter the number: 25
The given number 25 is an Automorphic Number.
"""