input: from typing import List
  from math import isqrt
  
  def max_distance_between_prime_indices(nums: List[int]) -> int:
      """
      Given an integer array nums, determine the greatest difference in indices between any two prime numbers within the array.
  
      Examples:
      >>> nums = [4,2,9,5,3]
      3
      >>> nums = [4,8,2,8]
      0
  
      Constraints:
      1 <= nums.length <= 3 * 10^5
      1 <= nums[i] <= 100
      It is guaranteed that nums contains at least one prime number.
      """
output:     
      def is_prime(n: int) -> bool:
          if n <= 1:
              return False
          if n == 2 or n == 3:
              return True
          if n % 2 == 0 or n % 3 == 0:
              return False
          i = 5
          while i * i <= n:
              if n % i == 0 or n % (i + 2) == 0:
                  return False
              i += 6
          return True
  
      prime_indices = [i for i, num in enumerate(nums) if is_prime(num)]
  
      return max(prime_indices) - min(prime_indices) if prime_indices else 0
  