All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Algorithms
Mental Math Competition (Posted on 2005-04-29) Difficulty: 5 of 5
At this year's state mental math competition, contestants will be given a prime number p<10,000 of the form 4k+1 and will be asked to find an integer x such that x²+1 is divisible by p, in less than 10 minutes. Each contestant will also be given access to two oracles:

Oracle 1: When given any integer n, outputs n².

Oracle 2: When given any integers m,n not divisible by p, outputs a number k such that kn-m is divisible by p. (In math-speak, this outputs m/n (mod p).)

Each oracle takes 1 second to respond.

You are going to enter this competition, but unfortunately, you are not great at mental math. In fact, all you know how to do in your head is add and subtract numbers. Furthermore, it takes you one second to perform such an operation.

Of course, you can also perform the most basic comparison operations in your head (m<n?, m>n?, m=n?). These also take you one second to perform.

Fortunately, you have a good short term memory, so you can keep track of and instantly access as many numbers in your head as you would like. Trying to fill your memory before the competition will be problematic, however, as your long term memory is bad.

How can you ensure success at this competition?

  Submitted by David Shin    
Rating: 2.2000 (5 votes)
Solution: (Hide)
We know by the two-squares theorem that p can be written in the form a²+b², where a and b are integers. We first find such an a and b by the following:

1. Set a=1, b=99, and compute a² and b².
2. Compute a²+b².
3. If a²+b²<p, set a := a+1, compute a², and return to step 2.
4. If a²+b²>p, set b := b-1, compute b², and return to step 2.
5. Output (a,b).

Note that we call Oracle 1 fewer than 100 times. We perform fewer than 100 increments/decrements (a := a+1 or b := b-1), perform fewer than 100 additions of the form a²+b² (step 2), and perform fewer than 200 comparisons. Thus, finding (a,b) takes fewer than 500 seconds.

After a and b have been found, use Oracle 2 to determine a/b (mod p). Note that (a/b)²+1=0 (mod p) since a²+b²=0 (mod p). Thus, a/b (mod p) is the desired value of x.

The total running time is fewer than 501 seconds, which is less than 10 minutes.

Comments: ( You must be logged in to post comments.)
  Subject Author Date
re: Possible solution, maybe?Alexis2005-10-30 10:31:13
Possible solution, maybe?Alexis2005-10-30 10:06:31
I haven't found solutionarmando2005-05-19 19:03:08
Some ThoughtsThoughts on Oracle 2Tristan2005-05-02 22:59:24
Some Thoughtssome things I noticedJer2005-05-02 17:44:43
A beginningTristan2005-05-02 05:39:20
I am noob.Amon2005-04-30 00:48:23
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (3)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information