Given a number N.Find the minimum Lucky number, the sum of whose digits is equal to N.
Note:-Lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. 
Example 1:
Input:
N=29
Output:
44777
Explanation:
44777 is the smallest number whose 
digit-sum(4+4+7+7+7) is equal to 29.
Example 2:
Input:
N=9
Output:
-1
Explanation:
There is no lucky number whose digit-sum
is equal to 9.
Your Task:
You don't need to read input or print anything.Your task is to complete the function minimumLuckyNumber() which takes a number N as input parameters and returns the minimum Lucky number(in the form of a string) whose digit-sum is equal to N. If there is no lucky number whose digit-sum is equal to N, then return -1.
Expected Time Complexity:O(N)
Expected Auxillary Space:O(1)
Constraints:
1<=N<=10^{5}
^{Note:The answer may not fit in 64 bit integer representations.}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3

class Solution:
    def minimumLuckyNumber(self,N):
        #code here

Solutions:
class Solution:

	def minimumLuckyNumber(self, N):
		(a, b) = (0, 0)
		s = ''
		while N > 0:
			if N % 7 == 0:
				a = a + 1
				N -= 7
			elif N & 4 == 0:
				b = b + 1
				N -= 4
			else:
				b = b + 1
				N = N - 4
		string = ''
		if N < 0:
			string = '-1'
			return string
		string += '4' * b + '7' * a
		return string


class Solution:

	def minimumLuckyNumber(self, N):
		g = []
		b = N // 4
		for i in range(b + 1):
			c = N - 4 * i
			if c % 7 == 0:
				return i * '4' + c // 7 * '7'
		return -1


class Solution:

	def minimumLuckyNumber(self, N):
		ans = ''
		for i in range(N // 4 + 1):
			rem = N - i * 4
			if rem % 7 == 0:
				for _ in range(i):
					ans += '4'
				for _ in range(rem // 7):
					ans += '7'
				return ans
		return '-1'


class Solution:

	def minimumLuckyNumber(self, n):
		(a, b) = (0, 0)
		s = 0
		while n > 0:
			if n % 7 == 0:
				n = n - 7
				b += 1
			elif n % 4 == 0:
				n = n - 4
				a += 1
			else:
				n = n - 7
				b = b + 1
		if n < 0:
			return '-1'
		else:
			string = ''
			string += '4' * a
			string += '7' * b
			return string
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.minimumLuckyNumber(N))


class Solution:

	def minimumLuckyNumber(self, N):
		n4 = 0
		n7 = 0
		while n4 <= N // 4:
			if (N - n4 * 4) % 7 == 0:
				n7 = (N - n4 * 4) // 7
				break
			n4 += 1
		if n4 * 4 == N:
			return '4' * n4
		return -1 if n7 == 0 else '4' * n4 + '7' * n7