TopCoder problem "PrimePolynom" used in SRM 259 (Division II Level Two)



Problem Statement

    

A prime number is an integer greater than 1 that has no positive divisors other than 1 and itself. The first prime numbers are 2, 3, 5, 7, 11, 13, 17, ...

It is known that no non-constant polynomial function P(n) exists that evaluates to a prime number for all integers n. But there are some famous quadratic polynomials that are prime for all non-negative integers less than M (M depends on the polynomial).

You will be given ints A, B and C. Your method should return the smallest non-negative integer M such that A*M2 + B*M + C is not a prime number.

 

Definition

    
Class:PrimePolynom
Method:reveal
Parameters:int, int, int
Returns:int
Method signature:int reveal(int A, int B, int C)
(be sure your method is public)
    
 

Constraints

-A will be between 1 and 10000, inclusive.
-B will be between -10000 and 10000, inclusive.
-C will be between -10000 and 10000, inclusive.
 

Examples

0)
    
1
-1
41
Returns: 41
This is one of the famous polynomials.
1)
    
1
1
41
Returns: 40
2)
    
1
1
-13
Returns: 0
No negative numbers are prime.
3)
    
1
-15
97
Returns: 48
4)
    
1
-79
1601
Returns: 80
The largest possible answer.

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=4475

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=8012&pm=4475

Writer:

Andrew_Lazarev

Testers:

PabloGilberto , lbackstrom , brett1479 , Olexiy

Problem categories:

Brute Force