Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- def isPrime(x):
- if(x==2):return True
- elif(x<2):return False
- for i in range(2,math.ceil(math.sqrt(x)+1)):
- if (x%i==0): return False
- return True
- def isPerfect(x):
- return math.ceil(math.sqrt(x))==math.sqrt(x)
- prime =[]
- perfect=[]
- other=[]
- for i in range(2,1000):
- if(isPrime(i)):
- prime.append(i)
- elif(isPerfect(i)):
- perfect.append(i)
- else:
- other.append(i)
- toBinary = lambda x: format(ord(x),'b').zfill(8)
- T = int(input())
- for c in range(T):
- x = input()
- a = "".join(toBinary(i) for i in x)
- i,j,k = 0,0,0
- ans = []
- for n in range(0,len(a),2):
- ind = a[n:n+2]
- if(ind == '11'):
- ans.append(prime[i])
- i+=1
- elif(ind == '00'):
- ans.append(perfect[j])
- j+=1
- else:
- ans.append(other[k])
- k+=1
- print("Case " , c+1 , " : ", ",".join(str(i) for i in ans))
Add Comment
Please, Sign In to add comment