What are the limits for the problems ? Are the programming contest problems ?

1.
If not too much .. precompute all primes till the limit and then you can easily find using binary search the higher and lower primes.

2.
Just create a binary tree and see ? Is that too much time ?

Let me know limits .. that would help

-Dhyanesh

On 3/25/06, Terry <[EMAIL PROTECTED]> wrote:

Hi,
Can you tell me how to solve the following 2 problems

Problem 1
Given a number (>5) print the prime closest to it.If there are 2
numbers that are closest,print the larger one.

Input
The first line contains the number of test cases

Each test case will contain a number

Output
Output the nearest prime

Example
Input:
2
14
99
Output:
13
101


Problem 4
Determine the height of the Binary Search Tree
that can be formed from the given sequence (this permutation)

Input
The first line contains the number of test cases n

Each test case will contain two lines.
The first line contains the number of integers in the sequence.
The next line contains the sequence of numbers separated by spaces.

Output
Output the height

Example
Input:
1
7

5 3 7 2 4 6 8
Output:
2


Regards
Terry




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to