
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
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 Articles
- 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 count odd numbers in an interval range using Python
- Find the number of divisors of all numbers in the range [1, n] in C++
- Program to find bitwise AND of range of numbers in given range in Python
- Java Program to get number of elements with odd factors in given range
- Count total divisors of A or B in a given range in C++
- Program to find out the number of special numbers in a given range in Python
- C Program to Check if count of divisors is even or odd?
- Java Program to check if count of divisors is even or odd
- Golang Program to Print Odd Numbers Within a Given Range
- Python Program for Number of elements with odd factors in the given range
- Find the Number Of Subarrays Having Sum in a Given Range in C++

Advertisements