Computer Science, asked by romanbiswajit721159, 8 months ago

two integers X and K. Varsha needs to determine whether there is an integer A such that it has exactly X positive integer divisors and exactly K of them are prime numbers.

Answers

Answered by UmangThakar
0

Answer: There can be infinite such numbers where it is possible that X is written as product of K distinct divisors.

Explanation:

Given in the question,

Varsha needs to determine whether there is an integer A such that it has exactly X positive integer divisors and exactly K of them are prime numbers.

Any number will always have 2 divisors irrespective of whether it is prime or it is composite, those two numbers are 1 and the number itself.

If the given number is a prime number then it is very clear that one of the divisor is that same prime number and the other number is 1 which is neither a prime number nor a composite number.

Similarly , if the given number is a non prime number then it will always have one or more divisor then which consists of both prime and composite numbers.

To explain it in a easy manner, here are some examples:

Let’s say the number is 90.

Its prime factors are 2,3 and 5.

Its composite and other factors are 1, 10, 18, 45 and 90.

Let’s say the number is 16.

It has only one prime factor, which is 2.

Its composite and other factors are 1, 4, 8, 16.

Hence, any given non-prime integer has some prime and some non-prime and other (1) divisors and any prime number has other (1) and prime divisor, which is itself.

There can be infinite such numbers where it is possible that X is written as product of K distinct divisors.

Answered by poojan
1

Program to find a number within range that  has exactly X positive integer divisors and exactly K of them are prime numbers.

Language used : Python Programming

Program :

n=int(input("Enter the range of numbers in which you need to check : "))

X=int(input("Enter no.of positive integers divisors the number need to have : "))

K=int(input("Enter no.of positive prime integers divisors the number need to have : "))

count1=0

count2=0

flag=0

l=[]

finallist=[]

st=""

for num in range(0,n):

 if num>1:

     for i in range(2,num):

         if (num % i) == 0:

             break

     else:

         l.append(num)

for i in range(1,n):

  for j in range(1,i+1):        

      if i%j==0:

          count1+=1

          if j in l:

              count2=count2+1

  if count1==X and count2==K:

      finallist.append(i)

  count1=0

  count2=0

if len(finallist)==0:

  st="None"

else:

  for i in finallist:

      st=st+str(i)+" ,"

  st=st[:-2]

print("Numbers within range which have exactly X, i.e. ",X," positive integer divisors and exactly K i.e., ",K," of them are prime numbers is/are :", st,".")

Inputs and outputs : (Various Testcases)

Input 1 :

Enter the range of numbers in which you need to check : 30

Enter no.of positive integers divisors the number need to have : 8

Enter no.of positive prime integers divisors the number need to have : 2

Output 1 :

Numbers within range which have exactly X, i.e.  8  positive integer divisors and exactly K i.e.,  2  of them are prime numbers is/are : 24 .

Input 2 :

Enter the range of numbers in which you need to check : 20

Enter no.of positive integers divisors the number need to have : 3

Enter no.of positive prime integers divisors the number need to have : 1

Output 2 :

Numbers within range which have exactly X, i.e.  3  positive integer divisors and exactly K i.e.,  1  of them are prime numbers is/are : 4 ,9 .

Input 3 :

Enter the range of numbers in which you need to check : 50

Enter no.of positive integers divisors the number need to have : 8

Enter no.of positive prime integers divisors the number need to have : 8

Output 3 :

Numbers within range which have exactly X, i.e.  8  positive integer divisors and exactly K i.e.,  8  of them are prime numbers is/are : None .

Explanation :

  • First take the range n, X and K values as input and prepare a list of prime till range n.

  • Then, write a loop that iterates till n, and with iterator variable i, and inner loop till the range i, such that i modulo jth value to get the divisiors count.

  • If you find i to be the divisor or then check if the divisor is a prime or not using the list prepared. If it is a prime, increment prime count.

  • If it is a prime, increment prime count. After the completion of one value, check X value with divisor count and K value with prime count. If they are equal, push them into a list of final values.

  • After the completion of the computations on every value within the range, print the values that satisfies the users input.

If you go through the test cases given,

When n=30, X=8, Y=2 is taken, it resulted 24 as the answer, as the number 24 has 8 divisors [1, 2, 3, 4, 6, 8 , 12, 24] in which 2 are prime divisors [2, 3]. 24 is the only number that satisfies the given data in the range.

Similarly, the other two cases too work.

Note : I have added the attachments of the interpretation and the execution of programs with their outputs. Take a look!

Quick Tip : In python, you must and should follow Indentation. Following the indentation property in any programming language will help you in quickly analysing the code, if an error occurs.

Learn More :

  • If you are new to python, and wants to try out for loop as a beginner, here we have a small gift for you.

        brainly.in/question/8287051

  • Want to check if a number is prime or not? Have a look at this beginner friendly code.

        brainly.in/question/15723722

Hope it helps you. Cheers!

Attachments:
Similar questions