Sunday, December 27, 2009

Programming question (for a certain penquin and co.)

To start off, more accurate would be co. and penquin, but that sounds weird.

Anyway, this question was inspired by both a simplish math question and a comment from C_o_s, whoever that is.

So you are given 2 integers a and b, which you want to express in the form of:

x!y!....weird!/c!d!...weirder!
(Recall that 3!=6, just like pi != pie)

C_o_s quickly realises this is trivial (say a!(b-1)!/b!(a-1)!) works.

Hence, he suggests limiting all of x, y, ..., c, d, .... to primes, not necessarily distinct. He thinks for another second, and realises that the proof of existence is simply trivial. Hence, he has raised (and solved 2 seconds later) the question of how many prime factorials are needed to express a/b in the desired form.

Eg1: 2/3= 2!2!/3!, hence the answer is 3.
Eg2: 3/5=3!3!2!/5!, hence the answer is 4.

Input: a number n, stating how many prime factors a has
a number m, stating how many prime factors b has
n numbers, which are the prime factors of a
n numbers, the powers of the prime factors of a
m numbers, which are the prime factors of b
m numbers, the powers of the prime factors of b

Bounds should be around 500 primes from the first 1000 primes. Powers should be at most 100?

VINTAGE (Very important note to all generic entrants): The test cases have not been created because C_o_s is suspected to be lazy.

No comments:

Post a Comment