
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python Program for Number of elements with odd factors in the given range
In this article, we will learn about the solution to the problem statement given below.
Problem statement − We are given a range, we need to find the number of odd factors in the range.
Approach
As we all know that all perfect squares have an odd number of factors in a range. So here we will compute a number of perfect squares.
As m and n both are inclusive, so to avoid error in case of n being a perfect square we take n-1 in the formulae.
Now let’s see the implementation below−
Example
# count function def count(n, m): return int(m**0.5) - int((n-1)**0.5) # main n = 25 m = 400 print("Number of odd squares are: ", count(n, m))
Output
Number of odd squares are: 16
All the variables and functions are declared in the global scope as shown in the figure above.
Conclusion
In this article, we have learned how we can find the number of elements with odd factors in a given range.
- Related Articles
- Java Program to get number of elements with odd factors in given range
- Python Program for Find sum of odd factors of a number
- Python Program to replace list elements within a range with a given number
- C Program for Find sum of odd factors of a number?
- C++ program for Find sum of odd factors of a number
- Program to find number of pairs where elements square is within the given range in Python
- Number of indexes with equal elements in given range in C++
- Python Program for Efficient program to print all prime factors of a given number
- Program to update elements in a given range in Python
- Python – Test for all Even elements in the List for the given Range
- Program to find count of numbers having odd number of divisors in given range in C++
- C++ program to find numbers with K odd divisors in a given range
- Python Program for Find minimum sum of factors of number
- Queries for counts of array elements with values in given range in C++
- Count number of smallest elements in given range in C++

Advertisements