Computer Science, asked by neelimabandaru, 1 year ago

You are given a list of N integers and another positive integer K. Write a program to compute the number of ways in which the product P of the given N integers can be expressed as a product of K positive integers (not necessarily distinct). The order of the factors in the expression is not important. For example, 1 x 2 x 3 and 2 x 3 x 1 are not counted as different ways of expressing 6 as a product of three integers.

Constraints
The product of the N integers <= 10^9
Each of the N integers <=5000

Input:

First line contains two space separated integers, N and K
The next line contains N space separated integers

Answers

Answered by Anonymous
1

The C program of the given code is as follows:

#include <stdio.h>

int p =0;

void product(int a ,int b ,int c)

{

   int q;  

   if( a = = 0 )

   {

       if( b <= c )

       {

           p++;

       return;

       }

   }

   else

   {

       if(b > c)

           return ;

       for(q=b ; q <= c ;q ++)          

       {

           if(c % q == 0 )

               product( a - 1, q , c/q);

       }

   }

}

int main()

{

  int o , a ,arr[10],c=1,b,q;

  scanf("%d%d",&o,&a);

  for(b=0; b<o; b++)

  {

      scanf("%d",&arr[b]);

      c = c *arr[b];

  }

  for(b =1; b <= c ; b++)

  {

       if(c % b ==0)

           product( a - 2, b ,c /b );

  }

  printf(" %d \n",c);

  return 0;

}

Similar questions