TopcoderArchive
SRM22 Aug 2005
SRM 259

PrimePolynom

Problem statement, definition, constraints, and public examples.

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

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