Finding number of integers which has exactly X divisors

Method 1: 

Code

import java.io.*;

import java.util.Scanner;

import java.util.*;

public class Prepinsta

{

static int 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(int n)
{

int c = 0;

for (int i = 1; i <= n; i++)

{

if (divisors(i) == 9)

{

System.out.print(i);

System.out.print(” “);

c = c + 1;

}

}

System.out.print(“\n\nTotal number of divisors= ” + c);

}

public static void main (String[] args)
{

int n;

System.out.print(“\nEnter the number of your choice  : “);

Scanner sc = new Scanner(System.in);

n = sc.nextInt();

System.out.print(“\n Number which has exactly 9 divisors are : “);

check(n);

}

}

Algorithm

  • Start
  • Iterate all numbers till n
  • Count the numbers that have exactly 9 divisors
  • Iterate till n
  •  Check if n is divisible by i
  • Increase value of count
  • Print count
  • Stop

Output

Output:

Enter the number of your choice :

100

The number which has exactly 9 divisors

36 100

Total number of divisors =2

Get Access To Our Premium Courses
Install our application from PlayStore and get discounts on our new courses.

Pin It on Pinterest