Prime Number Check and Fibonacci Series Generation

Problem Two short warm-up functions: (1) check whether a given number is prime; (2) generate the first N terms of the Fibonacci series.

Input / Output

  • Input: an integer n for the primality check; an integer N for the series length.
  • Output: isPrime(n) returns a boolean; fibonacci(N) returns a list of the first N Fibonacci terms.

Constraints

  • n fits in a 32-/64-bit integer; N up to ~90 before 64-bit overflow.
  • No library primality or memoisation helpers — write the loops yourself.
  • Handle boundaries explicitly: n < 2 is not prime; N = 0 returns an empty list.

Example

  • isPrime(17) → true; isPrime(1) → false; isPrime(2) → true (the only even prime).
  • fibonacci(6) → [0,1,1,2,3,5].
asked …
LeaderboardSalaryAccount
Prime Number Check and Fibonacci Series Generation · 2dbi