# Program to find the number of integers with exactly 9 divisors | faceprep

Given a number N, we need to find the total number of integers with exactly 9 divisors within the given range N.

Test cases:

Input:
100
Output:
2
36 100

Divisors of 36 = 1, 2, 3, 4, 6, 9, 12, 18, 36
Divisors of 100 = 1, 2, 4, 5, 10, 20, 25, 50, 100

## Number of Integers with exactly 9 divisors

// C program to find number of integers with exactly 9 divisors

#include
int count_no_of_divisors(int num)
{
int count = 0;
for (int i = 1; i <= num; i++)
{
if (num % i == 0)
count = count + 1;
}
return count;
}

void check_9_factors(int n)
{
int c = 0;
for (int i = 1; i <= n; i++)
{
if (count_no_of_divisors(i) == 9)
{
printf(“%d “, i);
c = c + 1;
}
}
printf(“\n\nTotal = %d\n”, c);
}

int main()
{
int n;
printf(“\nEnter the number : “);
scanf(“%d”, &n);
printf(“\nThe number which has exactly 9 divisors : “);
check_9_factors(n);
return 0;
}

// C++ program to find number of integers with exactly 9 divisors

#include
using namespace std;
int count_no_of_divisors(int num)
{
int count = 0;
for (int i = 1; i <= num; i++)
{
if (num % i == 0)
count = count + 1;
}
return count;
}

void check_9_factors(int n)
{
int c = 0;
for (int i = 1; i <= n; i++)
{
if (count_no_of_divisors(i) == 9)
{
cout << i << ” “;
c = c + 1;
}
}
cout << “\n\nTotal = ” << c;
cout << endl;
}

int main()
{
int n;
cout << “\nEnter the number : “;
cin >> n;
cout << “\nThe number which has exactly 9 divisors : “;
check_9_factors(n);

return 0;
}

// // Java program to find number of integers with exactly 9 divisors

import java.io.*;
import java.util.Scanner;
import java.util.*;
public class Main
{
static int count_no_of_divisors(int num)
{
int count = 0;
for (int i = 1; i <= num; i++)
{
if (num % i == 0)
count = count + 1;
}
return count;
}

static void check_9_factors(int n)
{
int c = 0;
for (int i = 1; i <= n; i++)
{
if (count_no_of_divisors(i) == 9)
{
System.out.print(i);
System.out.print(” “);
c = c + 1;
}
}
System.out.print(“\n\nTotal = ” + c);

}

public static void main (String[] args)
{
int n;
System.out.print(“\nEnter the number : “);
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
System.out.print(“\nThe number which has exactly 9 divisors : “);
check_9_factors(n);
}
}

// Python program to find number of integers with exactly 9 divisors

def count_of_no_of_divisors(num):
count = 0
for i in range(1, num+1):
if(num % i == 0):
count = count + 1
return count

def check_9_factors(n):
c = 0
for i in range(1, n+1):
if(count_of_no_of_divisors(i) == 9):
print(i, end= ” “)
c = c + 1
print(“Total : “, end = ” “)
print(c)

n = int(input(“Enter a number : ” ))
print(“The number which has exactly 9 divisors are “)
check_9_factors(n) 