2

Puzzle:

Given a function 'solve()' that accepts a single integer parameter, and returns an integer, write a program that determines if this function is an additive function [ solve($x+y$) = solve($x$) + solve($y$) ] for prime numbers below $100$.

In this case, $f(x+y)=f(x)+f(y)$ refers to an additive function, and the prime numbers below $100$ are $2, 3,5,7,11,13,17,19,23,29,31,37,41,43,47, \cdots,97$, so does that mean if $x=2$ and $y=5$ then $f(x+y)=f(x)+f(y$) holds true, and does it remains same for all pairs of prime numbers?

Please let me know if I am wrong.

Rangesh
  • 121
  • 1
    you seem to be right – Wonder Jul 19 '12 at 08:34
  • 1
    btw the key optimization that you can make would be to keep a hash map x -> f(x) so that you don't recompute solve() for an argument more than once. eg. f(22) will come up as both f(11) + f(11) and also as f(3) + f(19). Although you need to compute these values like f(3) separately, you should have to compute f(22) only once. – Wonder Jul 19 '12 at 08:44
  • 1
    The claim is ambiguously stated, but your interpretation looks likely. One alternative interpretation would only look at primes $x$ and $y$ for which $x+y$ is also prime, but that would be ridiculously restricted. – Harald Hanche-Olsen Jul 19 '12 at 08:46
  • has anyone answer this question? –  Nov 09 '12 at 00:14
  • @Yoo No one asked a question. OP asked whether she was wrong, and was told she wasn't. If you have a question to ask, you've not gone about it very well. – Gerry Myerson Nov 09 '12 at 00:20

0 Answers0