# Python program to find number of integers which has exactly x divisors

## Number of integers which has exactly x divisors

Numbers dividing with self or 1 are called prime numbers but numbers having multiple divisors are called composite numbers. In this python program, we will find the numbers with the exact number of divisors defined by the user. The divisor of a number is defined, when we divide a number1 by other number let number2 and gives remainder zero, so the number2 will be considered as the divisor of the number1. We will find the number of the divisor of the numbers and print them along with the count of numbers. ## Algorithm

• Step 1:- Start.
• Step 2:- Take user inputs like Number and Divisors.
• Step 3:- Initialize a count variable with zero value.
• Step 4:-Run a for loop with a range from 1 to Number+1.
• Step 5:- Initialize another count variable with zero.
• Step 6:- Run other for loop ranging from 1 to iterator of 1st for loop+1.
• Step 7:- Check for complete division conditions and if TRUE increment count2 by 1.
• Step 8:- Come out of for loop and check if count2 is equal to Divisor.
• Step 9:- If TRUE increment count1 by 1 and print the number with exact divisors.
• Step 10:- Print count1.
• Step 11:- End.

## Python Code

```#user inputs
Number = int(input('Enter range of number :'))
Divisor = int(input('Enter exact number of divisors :'))
#count1 is to count total number of Numbers with exact divisor
count1 = 0
#driver loop
for i in range(1,Number+1):
#count2 checks the total number of divisors
count2 = 0
#loop to find number of divisors
for j in range(1,i+1):
if i % j == 0:
count2+=1
else:
pass
if count2 == Divisor:
count1+=1
#end = " " is used so it can print Numbers in same line
print(i,end = " ")
#for break in line between Numbers and total count
print('')
print(count1)```
`Output:Enter range of number :30Enter exact number of divisors :34 9 253`

### 5 comments on “Python program to find number of integers which has exactly x divisors”

• Shubham

public class JavaApplication1
{
public static void main(String[] args)
{
Scanner obj = new Scanner(System.in);
int n,x;
n = obj.nextInt();
x = obj.nextInt();
for(int i=1;i<=n;i++)
{
int c=0;
String s="";
for(int j=1;j”+s);
System.out.println();
}
}
}
} 0
• Shubham

public class JavaApplication1
{
public static void main(String[] args)
{
Scanner obj = new Scanner(System.in);
int n,x;
n = obj.nextInt();
x = obj.nextInt();
for(int i=1;i<=n;i++)
{
int c=0;
String s="";
for(int j=1;j”+s);
System.out.println();
}
}
}
} 0
• Shubham

public class JavaApplication1
{
public static void main(String[] args)
{
Scanner obj = new Scanner(System.in);
int n,x;
n = obj.nextInt();
x = obj.nextInt();
for(int i=1;i<=n;i++)
{
int c=0;
String s="";
for(int j=1;j”+s);
System.out.println();
}
}
}
} 0
• Om Prakash

Code in Java :
import java.util.Scanner;
public class Exactly_n_divisors
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print(“Enter range: “);
int range = sc.nextInt();
System.out.print(“Enter exact number of divisors: “);
int exact = sc.nextInt();
int total = 0;
System.out.println(“Numbers which has exactly “+exact+ ” divisors are “);
for(int number=1; number<=range; number++)
{
int count = 0;
for(int divisor=1; divisor<=number; divisor++)
{
if(number%divisor == 0)
count++;
}
if(count == exact)
{
System.out.println(number+" ");
total++;
}
}
System.out.println("Total numbers: "+total);
}
} 0
• Shubham Kumar

#program in java

import java.util.*;
public class EqualDivisorInRange {

public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println(“Enter range: “);
int r=sc.nextInt();
System.out.println(“Enter maxm divisor of number: “);
int d=sc.nextInt();
int c[]=new int[r];
int k=0;
for(int i=1;i<=r;i++)
{
int count=0;
for(int j=1;j<=i;j++)
{
if(i%j==0)
{
count++;
}
}
if(count==d)
{
c[k]=i;
k++;
}

}
System.out.println("Number are with equal divisor: ");
for(int p=0;p<k;p++)
{
System.out.println(c[p]);
}
}

} 1