Optional 2 (Year 2 Sem 2)

Optional2 is the second optional in semester 2 of year 2, and the second optional in the total of year 2. It is an extension of Algorithms, and is considered to be moderately difficult.

Description
No description was provided for this optional.

Unlocked after completion
None

To unlock

 * Complete Lab 2 (Year 2 Sem 2)

Question
Question 1: Prime Power

Given a positive integer q, find whether q is a prime power. A number q is a prime power if and only if q = pk, where p is a prime number and k is a positive integer.

Implementation

Sample
 * Implement a function p_power
 * The input q is positve integer
 * The output the string"yes" is n is a prime power and string "no" otherwise


 * p_power(37) = "yes"
 * p_power(36) = "no"

Solution
To be a prime power, q must return a list of a list of length 1 (like 2,1 ) when passed through the function written in year 2 sem 2 lab 2 question 4. Then, the first number (a in a,b ) must be prime.

1 is not a prime power.

Question
Question 2: Number Game

You are playing the following simple game with a friend:

# The first player picks a positive integer X.

# The second player gives a list of k positive integers Y1,…,Yk such that (Y1+1)(Y2+1)⋯(Yk+1)=X, and gets k points.

Write a program that plays the second player.

Implementation

Sample
 * Implement a function n_game
 * The input X is a positive integer
 * The output K, giving the number of points obtained by the second player, assuming he/she plays as good as possible.


 * n_game (65536) = 16
 * n_game(127381) = 3

Solution
Pass X through the function written in year 2 sem 2 lab 2 question 4. Now, the output will look like [[a0, b0], [a1, b1] ... ].

Add up all the numbers labelled b0, b1..., and that is the answer.