Divisible by Last Digit
MediumPractice library · +20 XPmathnumber theoryhash map
Given a list of N positive integers, count how many numbers are divisible by their last digit. For a number X, its last digit is X % 10. If a number's last digit is 0, it is not considered divisible by 0 for this problem. Count such numbers.
Input
The first line contains an integer N (1 <= N <= 200000). The second line contains N space-separated positive integers a_1, a_2, ..., a_n (1 <= a_i <= 10^9).
Output
Print a single integer: the count of numbers divisible by their last digit.
Constraints
1 <= N <= 200000 1 <= a_i <= 10^9
Time limit 1 s (native code; slower languages get more)Memory 256 MB15 hidden tests
Example 1
Input
5 12 24 30 48 55
Output
4
12 is divisible by 2, 24 by 4, 48 by 8. 30 and 55 are not counted.
Example 2
Input
3 10 20 30
Output
0
No numbers are counted as their last digit is 0.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
5 12 24 30 48 55
Example 2 input
3 10 20 30