1

This is done by Python

Suppose we represent the sum of a collection of exponentiation operations as a list of tuples, where each tuple contains two integers: the base and the exponent. For example, the list [(2,4),(3,5),(-6,3)] represents the sum of powers 24 + 35 + (−6)3.

Implement a function sumOfPowers(nes, ps) that takes a list of one or more tuples nes (i.e., nes is of the form [(a1,n1),...,(ak,nk)]) as its first argument, and a list of one or more primes ps (i.e., of the form [p1,...,pm]) as its second argument. The function should return the correct result of the sum of powers as long as the following is true (e.g., on a computer with unlimited memory and time):

0 ≤ a1n1 + ... + aknk < p1 ⋅ ... ⋅ pm

You may assume the second list contains distinct prime numbers. You may not assume that the numbers in the first input list have any particular patterns or relationships; they can be in any order, they can be of any size, and they may or may not share factors. Your implementation must work efficiently on very large inputs

Cactus
  • 27,075
  • 9
  • 69
  • 149
Jason
  • 45
  • 5
  • there is a mistake in the third line in 1st paragraph: it should be 2^4 + 3^5 + (-6)^3 – Jason Feb 24 '15 at 23:46
  • work efficiently on very large inputs (e.g., with computations like 2^29999999999999999999999999999999996) – Jason Feb 24 '15 at 23:47
  • 1
    Well... what have you tried so far? What problems are you having? – Dyrborg Feb 24 '15 at 23:48
  • If you recall the CRT it should be fairly straightforward. What's your problem, exactly? – Stefano Sanfilippo Feb 24 '15 at 23:50
  • The problem is that how could I use the chinese reminder theorem to solve it in an efficiency way. – Jason Feb 24 '15 at 23:51
  • 1
    By... applying it? This is a direct application of the CRT, read again the theorem and try to understand it. This is likely an assignment, so you are supposed to do it by yourself. – Stefano Sanfilippo Feb 24 '15 at 23:52
  • Here is what I plan to do: computing the entire sum of powers modulo each of the prime numbers you are supplied (in parallel), and then at the end, using CRT to combine the final result of the sum of powers modulo each prime. Is that in the right direction? – Jason Feb 24 '15 at 23:56
  • Yep. That, or doing the CRT recombination before the sum. – Stefano Sanfilippo Feb 26 '15 at 14:30

0 Answers0