string-and-primes

Dark completed with studying Strings last night and trying to solve the problem of primes numbers from last three months but did not succeed every time he preferred to ask your help and same goes this time.

He likes to play a game with PRIMES AND STRINGS and he named the game as "PRIME ASCII CHARACTERS".

The rules are  as simple as finding the primes.

He wants you to read a string and delete all the characters whose ASCII VALUES is found to be a prime number.

Input:

The first line contains T, the number of test cases.
Followed by T lines each contains a single string 'S'.

Output:

For every test case print the string by removing the PRIME ASCII CHARACTERS.

print "NULL" If all the characters of a string are prime ascii characters.

Constraints:

1 ≤ T ≤ 10000
1 ≤ |S| ≤ 100000

Author : Darshak Mehta

Note: String contains only Alphabets both UPPER & LOWER CASES.

SAMPLE INPUT
4
MEHTA
Mehta
HELLO
hello

SAMPLE OUTPUT
MEHTA
Mht
HELL
hllo

Source: hackerearth | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
import sys
def prim(n):
	#print n
	for i in range (2,n/2+1):
		if n%i==0:
		   return 0
	return 1	   
t=int(input())

while t>0:
	t-=1
	check=0
	string = input()
	for i in range(len(string)):
		#print string[i],
		if prim(ord(string[i])) == 0:
			sys.stdout.write(string[i])
			check=1
	if(check==1):		
		sys.stdout.write('\n')
	else:
		print("NULL")
	#		string= string[:i-1]+string[i+1:]
		    


def sqrt(n):
	""" Efficient sqrt Algorithm """
	x = n
	y = (x + n / x) / 2
	while y < x:
		x = y
		y = (x + n / x) / 2
	return x
def isPrime(num):
		""" Primality Test Algorithm """
		if num<=1:
				return 0
		if num==2:
				return 1
		if num%2 == 0:
				return 0
		sRoot = sqrt(num*1.0)
		i=3
		while(i<=sRoot):
				if(num%i==0):
						return 0
	i+=2
		return 1
def removePrimeASCII(s):
	mstr=""
	diff = 0
	for i in s:
		ip = isPrime(ord(i))
		if ip == 1:
			continue;
		else:
			mstr+=i
	if len(mstr) == 0:
		print("NULL")
	else:
		print(mstr)
t=eval(input())
for i in range(0,t,1):
	s=input()
	removePrimeASCII(s)


t=int(input())
lis=[]
for i in range(t):
	lis.append(input())
##making a list of prime numbers till 128
prime=[2,3]
for i in range(5,128,2):
	for j in prime:
		if i%j==0:
			break
	else:
		prime.append(i)
for i in range(t):
	string=lis[i]
	new=''
	for j in string:
		if ord(j) in prime:
			pass
		else:
			new=new+j
	if new!='':
		print(new)
	else:
		print("NULL")
	


import math

def primes(n):
	""" Returns  a list of primes < n """
	sieve = [True] * n
	for i in range(3,int(n**0.5)+1,2):
		if sieve[i]:
			sieve[i*i::2*i]=[False]*((n-i*i-1)/(2*i)+1)
	return [2] + [i for i in range(3,n,2) if sieve[i]]
	
arr = primes(257)

t = eval(input())
for i in range(t):
	s = input().strip()
	sum = ""
	for i in s:
		if ord(i) in arr:
			pass
		else:
			sum += i
	if sum == "":
		print("NULL")
	else:
		print(sum)


prime=[67,71,73,79,83,89,97,101,103,107,109,113]
t=eval(input())
while(t!=0):
	t-=1
	x=''
	s=list(input())
	for i in s:
		if ord(i) not in prime:
			x+=i
	if len(x)!=0:
		print(x)
	else:
		print("NULL")


def prime(x):
	if x==1:
		return 1
		
	i=2
	while i<x:
		if x%i==0:
			break
		i=i+1
	if i!=x:
		return 1 
	else:
		return 0
test=eval(input())
while test:
	lst=[]
	line=input()
	l=len(line)
	i=0
	while i<l:
		if prime(ord(line[i]))!=0:
			lst.append(line[i])
		i+=1
	s=""
	
	st="".join(lst)
	if s==st:
		print("NULL")
	else:
		print(st)
	test=test-1
			


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
def isPrime(n):
	for i in range(2,n):
		if n% i == 0:
			return 1
	return 0

n = int(input())
i=0
str = []
out = []
while i < n:
	str.append(input())
	i+=1
	

for s in str:
	temp=""
	for c in s:
		if isPrime(ord(c)) == 1:
			temp+=c
			
	out.append(temp)
	
for i in out:
	if i:
		print(i)
	else:
		print("NULL")


import string
import math

def is_prime(n):
	for i in range(2, int(math.sqrt(n) + 1)):
		if n%i == 0:
			return False
	return True


d = {}

for i in string.ascii_letters:
	d[i] = is_prime(ord(i))


tc = int(input())

for i in range(tc):
	s = ''
	for j in input():
		if d[j] == False:
			s += j
	if len(s) == 0:
		print('NULL')
	else:
		print(s)


t= eval(input())
table=['C','G','I','O','S','Y','a','e','g','k','m','q']
while t:
	t-=1
	s=input()
	r=""
	for i in range(0, len(s)):
		if table.count(s[i])==0:
			r+=s[i]
	if len(r)==len(s):
		print("NULL")
	else:
		print(r)
			


s="""2      3      5      7     11     13     17     19     23     29 
	31     37     41     43     47     53     59     61     67     71 
	73     79     83     89     97    101    103    107    109    113 
    127    131    137    139    149    151    157    163    167    173 
    179    181    191    193    197    199    211    223    227    229 
    233    239    241    251    257    263    269    271    277    281 
    283    293    307    311    313    317    331    337    347    349 
    353    359    367    373    379    383    389    397    401    409 
    419    421    431    433    439    443    449    457    461    463 
    467    479    487    491    499    503    509    521    523    541 
    547    557    563    569    571    577    587    593    599    601 """
primes =[int(x) for x in  s.split()]
t = eval(input())
while t:
	t-=1
	s=input()
	res=""
	there = False
	for x in s:
		ascii = ord(x)
		if ascii in primes:
			there = True
		else:
			res=res+x
	if not there:
		print("NULL")
	else:
		print(res)
			


def sqrt(n):

	x = n
	y = (x + n / x) / 2
	while y < x:
		x = y
		y = (x + n / x) / 2
	return x
def isPrime(num):

		if num<=1:
				return 0
		if num==2:
				return 1
		if num%2 == 0:
				return 0
		sRoot = sqrt(num*1.0)
		i=3
		while(i<=sRoot):
				if(num%i==0):
						return 0
	i+=2
		return 1
def removePrimeASCII(s):
	mstr=""
	diff = 0
	for i in s:
		ip = isPrime(ord(i))
		if ip == 1:
			continue;
		else:
			mstr+=i
	if len(mstr) == 0:
		print("NULL")
	else:
		print(mstr)
t=eval(input())
for i in range(0,t,1):
	s=input()
	removePrimeASCII(s)


import math
def is_prime(n):
	if n==2:
		return True
	elif n%2==0:
		return False
	else:
		for x in range(3, int(math.sqrt(n)+1), 2):
			if n%x==0:
				return False
		return True

i=eval(input())
#print i
for _ in range(0,i):
	case=list(input())
	temp=''
	for y in range(0,len(case)):
		if not is_prime(ord(case[y])):
			temp+=case[y]
	if len(temp):
		print(temp)
	else:
		print('NULL')


import math
a = eval(input())
while a > 0:
	s = input()
	n = ''
	for i in s:
		if not all(ord(i)%j != 0 for j in range(2,int(math.sqrt(ord(i))+1))):
			n += i
	if n != '':
		print(n)
	else:
		print("NULL")
	a -= 1
	


t=eval(input())
for kases in range(t):
	 s=input()
	 a=[67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113]
	 c=[]
	 for i in s:
	 	if ord(i) not in a:
	 		c.append(i)
	 d=''.join(c)
	 if s==d:
	 	 print("NULL")
	 else:
	 	 print(d)


t1=eval(input())
a=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149]
b=[0]*151
for i in range(0,len(a)):
	b[a[i]]=1
while t1>0:
	s=input()
	l=len(s)
	t=""
	for i in range(0,l):
		x=ord(s[i])
		if b[x]==0:
			t=t+s[i]
	if t==s:
		print("NULL")
	else:
		print(t)
	t1-=1



s="""2      3      5      7     11     13     17     19     23     29 
	31     37     41     43     47     53     59     61     67     71 
	73     79     83     89     97    101    103    107    109    113 
    127    131    137    139    149    151    157    163    167    173 
    179    181    191    193    197    199    211    223    227    229 
    233    239    241    251    257    263    269    271    277    281 
    283    293    307    311    313    317    331    337    347    349 
    353    359    367    373    379    383    389    397    401    409 
    419    421    431    433    439    443    449    457    461    463 
    467    479    487    491    499    503    509    521    523    541 
    547    557    563    569    571    577    587    593    599    601 """
primes =[int(x) for x in  s.split()]
t = eval(input())
while t:
	t-=1
	s=input()
	res=""
	there = False
	for x in s:
		ascii = ord(x)
		if ascii in primes:
			there = True
		else:
			res=res+x
	if not there:
		print("NULL")
	else:
		print(res )
			


i=3
ctr=1
arr=[2]
crr=[0]*301
crr[2]=1
sm=2
while i<=300:
	cnt=0
	if i%2!=0:
		j=0
		while j<ctr and arr[j]<=pow(i,0.5):
			if i%arr[j]==0:
				cnt=1
				break
			j=j+1
		if cnt==0:
			arr.append(i)
			crr[i]=1
			ctr=ctr+1
	i=i+1
t=eval(input())
i=0
while i<t:
	s=input()
	j=0
	cnt=0
	ans=[]
	while j<len(s):
		if crr[ord(s[j])]==1:
			cnt=1
		else:
			ans.append(s[j])
		j=j+1
	if cnt==1:
		print(''.join(ans))
	else:
		print("NULL")
	i=i+1


from sys import stdin
from math import sqrt
def is_prime(a):
	x = True
	s=int(sqrt(a))
	for i in range(2, s+1):
	   if a%i == 0:
		   x = False
		   return x
		   break
	return x
l=int(stdin.readline())
for i in range(0,l):
	a=stdin.readline()
	b=[ord(c) for c in a]
	if i!=l-1:
		b.pop()
	s=0
	po=False
	i=0
	while i<len(b):
		if is_prime(b[i]):
			b.remove(b[i])
			po=True
			s+=1
		i+=1
		if po:
			i-=1
			po=False
	if s==0:
		print('NULL')
	else:
		print(''.join(chr(i) for i in b))