You are given a large number N in the form of a string, you have to check whether it is divisible by 999 without dividing or finding modulo of number by 999.
 
Example 1-
Input:
N = 1998
Output:
Divisible
 
Example 2 -
Input:
N = 99999999
Output:
Not divisible
 
Your Task :
Complete the function isDivisible999() that receives a string N denoting number and returns true if the n is divisible by 999 and flse otherwise. The driver code itself prints "Divisible" if the returned value is true and returns "Non Divisible" if returned value is false.
 
Expected Time Complexity : O(len(N))
Expected Space Complexity : O(1)
 
Constraints:
1<=|N|<=10^{3}

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Mathematics

Starter code: #User function Template for python3



class Solution:



    def isDivisible999(self, N):

        # code here

Solutions:
class Solution:

	def isDivisible999(self, N):
		n = int(N)
		return n % 999 == 0


class Solution:

	def isDivisible999(self, N):
		a = int(N)
		if a % 999 == 0:
			return 1
		else:
			return 0


class Solution:

	def isDivisible999(self, N):
		a = int(N)
		if a % 999 == 0:
			return True
		return False


class Solution:

	def isDivisible999(self, N):
		y = int(N)
		if y % 999 == 0:
			return True
		else:
			return False


class Solution:

	def isDivisible999(self, N):
		N = int(N)
		if N % 27 == 0 and N % 37 == 0:
			return True
		else:
			return False


class Solution:

	def isDivisible999(self, N):
		a = int(N)
		return not a % 999


class Solution:

	def isDivisible999(self, N):
		x = int(N, 10)
		if x % 999 == 0:
			return 1
		else:
			return 0


class Solution:

	def isDivisible999(self, N):
		num = int(N)
		ele = num % 999
		if ele == 0:
			return 1
		else:
			return 0


class Solution:

	def isDivisible999(self, n):
		return 0 if int(n) % 999 else 1


class Solution:

	def isDivisible999(self, N):
		N = int(N)
		if N % 9 == 0 and N % 111 == 0:
			return True
		else:
			return False


class Solution:

	def isDivisible999(self, N):
		div = int(N) % 999
		if div == 0:
			return 1
		return 0