Provided a String of length N, your task is to find out whether or not the given string is a prime string. A prime string is a string in which the sum of the ASCII value of all the characters is prime.
Example 1:
Input: N = 13, S = "geeksforgeeks"
Output: YES
Explanation: As sum of ASCII is 1381,
which is prime.
Ã¢â¬â¹Example 2: 
Input: India
Output: NO
Explanation: As sum of ASCII is 485,
which is not prime.
Your Task:  
You don't need to read input or print anything. Your task is to complete the function isPrimeString() which takes the length of string and the string as inputs and returns true if that is a prime string, else false.
Expected Time Complexity: O(|S|)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ |S| ≤ 10^{6}

Source: geeksforgeeks | Difficulty: EASY
Tags: Number theory

Data structures

String algorithms

Starter code: #User function Template for python3

class Solution:
    def isPrimeString(self, s):
        # code here

Solutions:
class Solution:

	def isPrimeString(self, s):
		x = 0
		for i in range(len(s)):
			x = x + ord(s[i])
		for j in range(2, x):
			if x % j == 0:
				return False
				break
		else:
			return True


class Solution:

	def isPrimeString(self, s):
		c = 0
		l = list(s)
		for i in l:
			c += ord(i)
		if c <= 1:
			return False
		for i in range(2, c):
			if c % i == 0:
				return False
		return True


import math

class Solution:

	def isPrimeString(self, s):
		p = 0
		list1 = [ord(i) for i in s]
		q = sum(list1)
		flag = 0
		for i in range(2, int(math.sqrt(q))):
			if q % i == 0:
				flag = 1
				break
		if flag == 0:
			return True
		return False


class Solution:

	def isPrimeString(self, s):
		su = 0
		for i in s:
			su += ord(i)
		for i in range(2, int(su ** (1 / 2)) + 1):
			if su % i == 0:
				return 0
		return 1


class Solution:

	def isPrimeString(self, s):
		sum = 0
		for i in s:
			sum += ord(i)
		for i in range(2, sum // 2):
			if sum % i == 0:
				break
		else:
			return True
		return False


class Solution:

	def isPrimeString(self, s):
		sum = 0
		for i in range(len(s)):
			sum += ord(s[i])
		fact = 0
		for i in range(2, sum):
			if sum % i == 0:
				return 0
		return 1


class Solution:

	def isPrimeString(self, s):
		sum = 0
		for i in s:
			sum = sum + ord(i)
		for j in range(2, int(sum ** 0.5) + 1):
			if sum % j == 0:
				return False
		else:
			return True


from math import sqrt

class Solution:

	def isPrimeString(self, s):
		num = 0
		for i in range(len(s)):
			num += ord(s[i])
		if num % 2 == 0:
			return False
		limit = sqrt(num)
		i = 3
		while i <= limit:
			if num % i == 0:
				return False
			i += 2
		return True


class Solution:

	def isPrimeString(self, s):
		a = 0
		for i in s:
			a += ord(i)
		if a > 1:
			for i in range(2, a):
				if a % i == 0:
					return False
			return True
		return False


class Solution:

	def isPrime(self, n):
		prime = True
		if n == 1:
			return False
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				prime = False
				break
		if prime:
			return True
		else:
			return False

	def isPrimeString(self, s):
		sum = 0
		for i in s:
			sum += ord(i)
		p = self.isPrime(sum)
		return p


class Solution:

	def isPrimeString(self, s):
		v = 0
		for i in range(len(s)):
			v = v + ord(s[i])
		for j in range(2, v):
			if v % j == 0:
				return 0
				break
		else:
			return 1


class Solution:

	def isPrimeString(self, s):
		k = 0
		for i in s:
			k += ord(i)
		import math
		if k < 2:
			return False
		a = int(math.sqrt(k))
		for i in range(2, a + 1):
			if k % i == 0:
				return False
		return True


class Solution:

	def isPrimeString(self, s):
		o = 0
		c = 0
		for i in range(len(s)):
			o += ord(s[i])
		if o <= 1:
			return 0
		for i in range(2, int(o ** 0.5) + 1):
			if o % i == 0:
				return 0
		return 1


class Solution:

	def isPrimeString(self, s):
		import math

		def prime(n):
			if n == 1 or n == 0:
				return False
			k = int(math.sqrt(n))
			c = 0
			for i in range(2, k + 1):
				if n % i == 0:
					c += 1
			if c == 0:
				return True
			else:
				return False
		sum = 0
		for i in s:
			sum += ord(i)
		if prime(sum):
			return True
		else:
			return False


class Solution:

	def isPrimeString(self, n):
		import math
		sum = 0
		for i in n:
			sum = sum + ord(i)
		if sum < 2:
			return False
		s = int(math.sqrt(sum))
		for i in range(2, s + 1):
			if sum % i == 0:
				return False
		return True


import math

class Solution:

	def isPrimeString(self, s):
		v = 0
		for i in s:
			v = v + ord(i)
		if v < 2:
			return False
		for i in range(2, int(math.sqrt(v))):
			if v % i == 0:
				return False
		return True


import math

class Solution:

	def isPrimeString(self, s):
		lst = []
		for i in s:
			lst.append(ord(i))
		suum = sum(lst)
		b = int(math.sqrt(suum))
		for m in range(2, b + 1):
			if suum % m == 0:
				return False
		return True


class Solution:

	def isPrimeString(self, s):
		stg = 0
		for i in s:
			stg += ord(i)
		if stg <= 1:
			return False
		for i in range(2, int(stg ** 0.5) + 1):
			if stg % i == 0:
				return False
		return True


class Solution:

	def isPrimeString(self, s):
		asc = 0
		count = 0
		for i in s:
			asc = asc + ord(i)
		if asc == 1:
			return 0
		sq = int(asc ** 0.5)
		for j in range(2, sq + 1):
			if asc % j == 0:
				return 0
		return 1


class Solution:

	def isPrimeString(self, s):
		import math
		x = 0
		for i in s:
			x = x + ord(i)
		for j in range(2, int(math.sqrt(x)) + 1):
			if x % j == 0:
				return False
		return True


from math import sqrt

class Solution:

	def isPrimeString(self, s):

		def prime(n):
			if n < 2:
				return False
			for i in range(2, int(sqrt(n)) + 1):
				if n % i == 0:
					return 0
			return 1
		c = 0
		for j in s:
			c += ord(j)
		if prime(c) == True:
			return True
		return False


import math

class Solution:

	def isPrimeString(self, s):
		l = 0
		k = 0
		for i in s:
			l = l + ord(i)
		for j in range(2, int(math.sqrt(l) + 1)):
			if l % j == 0:
				k += 1
		if k != 0 or l == 1:
			return False
		else:
			return True


import math

class Solution:

	def isPrimeString(self, s):
		c = 0
		l = list(s)
		a = c = 0
		for i in l:
			a = a + ord(i)
		s = int(math.sqrt(a))
		for i in range(2, s + 1):
			if a % i == 0:
				c = c + 1
		if c == 0:
			return True
		else:
			return False


import math

class Solution:

	def isPrimeString(self, s):
		p = 0
		for i in s:
			p = p + ord(i)
		c = 0
		q = int(math.sqrt(p))
		for i in range(2, q + 1):
			if p % i == 0:
				return False
		return True


import math

class Solution:

	def isPrimeString(self, s):
		p = 0
		for i in s:
			a = ord(i)
			p = p + a
		if p < 2:
			return 0
		for i in range(2, int(math.sqrt(p)) + 1):
			if p % i == 0:
				return 0
		return 1


import math

class Solution:

	def isPrimeString(self, s):
		v = list(s)
		k = 0
		for i in v:
			k += ord(i)
		if k < 2:
			return 0
		for i in range(2, int(math.sqrt(k)) + 1):
			if k % i == 0:
				return 0
		return 1


import math as m

class Solution:

	def isPrimeString(self, s):
		sum = 0
		for i in s:
			sum += ord(i)
		num = int(m.sqrt(sum))
		if sum <= 2:
			return 0
		else:
			for i in range(2, num + 1):
				if sum % i == 0:
					return False
			return True


import math

class Solution:

	def isPrimeString(self, s):
		ascii_sum = sum((ord(c) for c in s))
		if ascii_sum < 2:
			return False
		for i in range(2, int(ascii_sum ** 0.5) + 1):
			if ascii_sum % i == 0:
				return False
		return True


import math

class Solution:

	def isPrimeString(self, s):
		sum = 0
		for i in s:
			sum += ord(i)
		f = 1
		if sum == 1:
			f = 0
		for i in range(2, int(math.sqrt(sum)) + 1):
			if sum % i == 0:
				f = 0
				break
		return f


class Solution:

	def isPrimeString(self, s):
		import math as m
		sum = 0
		l = list(s)
		for i in l:
			sum += ord(i)
		if sum < 2:
			return False
		e = int(m.sqrt(sum))
		for j in range(2, e + 1):
			if sum % j == 0:
				return False
		return True