Sum of Digits – Divisible by K: The program must accept two integers N and K as the input. The program must print the count of integers from 1 to N having the sum of digits divisible by K.
Boundary Condition(s):
1 <= N <= 10^5
1 <= K <= 100
Input Format:
The first line contains N and K separated by a space.
Output Format:
The first line contains an integer representing the count of integers from 1 to N having the sum of digits divisible by K.
Example Input/Output 1:
Input:
30 4
Output:
6
Explanation:
Here N = 30 and K = 4.
There are 6 integers from 1 to 30 having the sum of digits divisible by 4.
4 8 13 17 22 26
So 6 is printed as the output.
Example Input/Output 2:
Input:
100 10
Output:
9
Explanation:
Here N = 100 and K = 10.
There are 9 integers from 1 to 100 having the sum of digits divisible by 10.
19 28 37 46 55 64 73 82 91
So 9 is printed as the output.
N,K=map(int,input().split())
Temp=0
for foo in range(1,N+1):
c=0
for bar in str(foo):
c+=int(bar)
if c%K==0:
Temp+=1
print(Temp)
Leave a Reply