Problem: trial_division_naive

Your task is to implement a basic Primality Test and verify its correctness in Dafny. Preconditions: The input n is a non-negative integer (simulating unsigned types). Requirements: Implement the method check_prime which returns true if n is prime and false otherwise. (1) Algorithm: You should use a simple trial division loop that checks every integer from 2 up to $n-1$. (2) Functional Correctness: You must verify that your result matches the mathematical definition of primality (a number $n > 1$ divisible only by 1 and itself). Verification Challenges: (1) Loop Invariant: You must maintain an invariant stating that "for all $k$ checked so far ($2 \le k < i$), $k$ does not divide $n$". (2) Quantifier Instantiation: When the loop finishes without finding a divisor, you must prove that this implies the universal quantifier $\forall d. 1 < d < n \implies n \% d \neq 0$.

// Following is the block for necessary definitions
// <preamble>
predicate divides(d: int, n: int)
  requires d != 0
{
  n % d == 0
}

predicate is_prime(n: int)
{
  n > 1 &&
  forall d :: 1 < d < n ==> !divides(d, n)
}
// </preamble>

// Following is the block for potential helper specifications
// <helpers>

// </helpers>

// Following is the block for proofs of lemmas
// <proofs>

// </proofs>

// Following is the block for the main specification
// <spec>
method check_prime(n: int) returns (res: bool)
  // Simulate u64: input is non-negative
  requires n >= 0
  ensures res == is_prime(n)
// </spec>
// <code>
{
  // Implement and verify the algorithm to check for primality by naively testing divisibility for all integers from 2 to n-1
}
// </code>

method Main() {
}