

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to find count of numbers having odd number of divisors in given range in C++
In this tutorial, we will be discussing a program to find the count of numbers having odd number of divisors in a given range.
For this we will be provided with the upper and lower limits of the range. Our task is to calculate and count the number of values having an odd number of divisors.
Example
#include <bits/stdc++.h> using namespace std; //counting the number of values //with odd number of divisors int OddDivCount(int a, int b){ int res = 0; for (int i = a; i <= b; ++i) { int divCount = 0; for (int j = 1; j <= i; ++j) { if (i % j == 0) { ++divCount; } } if (divCount % 2) { ++res; } } return res; } int main(){ int a = 1, b = 10; cout << OddDivCount(a, b) << endl; return 0; }
Output
3
- Related Questions & Answers
- C++ program to find numbers with K odd divisors in a given range
- Find numbers with K odd divisors in a given range in C++
- Program to count number of common divisors of two numbers in Python
- PHP program to find the sum of odd numbers within a given range
- Program to find bitwise AND of range of numbers in given range in Python
- Find the number of divisors of all numbers in the range [1, n] in C++
- Average of odd numbers till a given odd number?
- Program to count odd numbers in an interval range using Python
- Java Program to get number of elements with odd factors in given range
- Find the Number Of Subarrays Having Sum in a Given Range in C++
- Count of N-digit Numbers having Sum of even and odd positioned digits divisible by given numbers - JavaScript
- Program to find out the number of special numbers in a given range in Python
- Python - Find the number of prime numbers within a given range of numbers
- Golang Program to Print Odd Numbers Within a Given Range
- Find the Number Of Subarrays Having Sum in a Given Range using C++
Advertisements