Introduction
Finding the sum of digits of a number can be done easily. Here we will be discussing a problem where the concept of finding the sum of digits will be mainly used. The concept of the modulo operator is required here. First, we will understand the problem statement clearly. Then solution approach will be described along with its C++ implementation.
Problem statement
You are given a range of integers [L, R]. Form the given range of integers, you need to find how many integers have the sum of digits of its square equal to the square of the sum of digits.
Input
L=1, R=20
Output
8
Explanation
For the range [1, 20], the numbers that are satisfying the above condition are 1, 2, 3, 10, 11, 12, 13, 20.
So, the count of such numbers is 8.
Note: Please try to solve the problem first and then see the below solution approach.
Also see, Euclid GCD Algorithm