650 - CS135501_I2P2014_LAB_8 Scoreboard

Time

2014/11/24 16:00:00 2014/11/24 17:10:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
10277 pick and multiply

10277 - pick and multiply   

Description

 Given N prime numbers, pick M prime numbers at each round and print out all the possible products.

Input

There will be two numbers in the first line, N and M, representing N prime numbers and multiply M numbers.
M means that you have to pick M numbers to multiply.
Second line will be N numbers, each representing a prime number.
You have to print the results in the following way:
Pick the prime numbers from head to tail
You "do not" have to sort the result.
In our sample input,
first round: multiply 2 and 3, and you get the product 6
second round: multiply 2 and 5, and you get the product 10
third round: multiply 2 and 7, and you get the product 14
forth round: because all the products starting from the first prime number are done, we start from the second prime number
    and multiply 3 and 5, and you get the product 15
fifth round: multiply 3 and 7, and you get the product 21
sixth round: same as previous calculation, we start from the third prime number 5,
    multiply 5 and 7, and we get the final result 35.
Because all possible products are calculated, the program is finished.
 
restriction of the input:
1
A prime number cannot be picked twice.

hint:

#include

int calc(int size, int leaveNum, int cur, int mul);

int arr[10];

int main()
{
        int n, pick;
        int i, j;
        scanf("%d %d", &n, &pick);
        for(i=0; i

You can follow the procedure:

I: create a for-loop, iterating the arr from cur to size.

II: in the for-loop,

        i : pick a number in arr at present iteration

        ii : determine the conditions, if we have to keep picking number, and cur is not the last prime number, continue to next recursion(don't forget that you have to modify the variables, which are passed to next recursion)

        iii: if we have picked M numbers, we can print out the product.

        iv : else, do nothing

Output

The products from M prime numbers' combination.

Remember there is a newline in the end.

Sample Input  Download

Sample Output  Download

Tags




Discuss