A Smith number is a composite number, the sum of whose digits is the sum of the digits of its prime factors obtained as a result of prime factorization (excluding ${1}$). The first few such numbers are ${4}$, $22$, $27$, $58$, $85$, ${94}$, and ${121}$.

Example: 

$378=2\times3\times3\times3\times7$ 

So, its prime factors are $2$, $3$, $3$, $3$, and $7$. 

The sum of its digits is $(3+7+8)=18$. 

The sum of the digits of its factors is $(2+3+3+3+7)=18$.  

Similarly, $4937775$ is a Smith number. 

$4937775=3\times5\times5\times65837$, and the sum of its digits is the same as the sum of the digits of its prime factors: $4+9+3+7+7+7+5=3+5+5+6+5+8+3+7=42$.

Task: 

Write a program to check whether a given integer is a Smith number.

Input Format

There will be only one line of input: $N$, the number which needs to be checked.

Constraints: 

$0<N<2,147,483,647$ (max value of an integer of the size of ${4}$ bytes)

Output Format

${1}$ if the number is a Smith number. 

${0}$ if the number is a not Smith number.  

Sample Input

378 

Sample Output

1

Explanation

Its prime factors are $2$, $3$, $3$, $3$, and $7$. 

The sum of its digits is $(3+7+8)=18$. 

The sum of the digits of its factors is $(2+3+3+3+7)=18$.

Difficulty: EASY
Tags: Number theory

Starter code:

Solutions:
import math

def findsum(a):
	r = 0
	for g in range(len(a)):
		r += int(a[g])
	return r
k = int(input(''))
n = k
ans = findsum(str(n))
for y in range(2, int(math.sqrt(k) + 1)):
	while k % y == 0:
		k /= y
		ans -= findsum(str(y))
if k != 1:
	ans -= findsum(str(int(k)))
if ans == 0:
	print(1)
else:
	print(0)


def digits(n):
	digits = []
	while n:
		digits.append(n % 10)
		n //= 10
	return list(reversed(digits))

def flat_list(l):
	return [item for sublist in l for item in sublist]

def is_smith_number(n):
	prime_factors = flat_list([digits(factor) for factor in factors(n)])
	n_digits = digits(n)
	return sum(prime_factors) == sum(n_digits)
	return True

def factors(n):
	primes = []
	p = 2
	while p ** 2 <= n:
		while n % p == 0:
			primes.append(p)
			n //= p
		p += 1
	if n > 1:
		primes.append(n)
	return primes
num = int(input())
print(1) if is_smith_number(num) else print(0)


n = int(input())

def digisum(n):
	return sum([int(s) for s in str(n)])

def getfactors(n):
	f0 = 2
	result = []
	while f0 ** 2 <= n:
		while n % f0 == 0:
			result.append(f0)
			n = n // f0
		f0 = f0 + 1
	if n > 1:
		result.append(n)
	return result
if digisum(n) == sum([digisum(i) for i in getfactors(n)]):
	print('1')
else:
	print('0')


def primes(n):
	primfac = []
	d = 2
	while d * d <= n:
		while n % d == 0:
			primfac.append(d)
			n //= d
		d += 1
	if n > 1:
		primfac.append(n)
	return primfac

def digits(n):
	return list(map(int, list(str(n))))
numToCheck = int(input())
primeFacts = primes(numToCheck)
for factor in range(len(primeFacts)):
	digs = digits(primeFacts.pop(0))
	for digit in digs:
		primeFacts.append(digit)
if sum(digits(numToCheck)) == sum(primeFacts):
	print(1)
else:
	print(0)


x = int(input())
ds = sum((int(y) for y in str(x)))
factors = []
for d in range(2, x):
	if x == 1:
		break
	while x % d == 0:
		factors.append(d)
		x //= d
print(int(ds == sum((sum((int(y) for y in str(f))) for f in factors))))


import sys
n = int(input())
n2 = str(n)
first_sum = 0
for number in n2:
	first_sum = first_sum + int(number)
primfac = []
d = 2
while d * d <= n:
	while n % d == 0:
		primfac.append(d)
		n //= d
	d += 1
if n > 1:
	primfac.append(n)
second_sum = 0
for prime in primfac:
	prime2 = str(prime)
	for number in prime2:
		second_sum = second_sum + int(number)
if first_sum == second_sum:
	print('1')
else:
	print('0')


smith_num = int(input())
from math import sqrt

def prime_factorization(num):
	list_factors = []
	for i in range(2, int(sqrt(num)) + 1):
		while num % i == 0:
			list_factors.append(i)
			num //= i
	if num != 1:
		list_factors.append(num)
	return list_factors

def sum_digits(num):
	str_num = str(num)
	sum_of_digits = 0
	for i in str_num:
		sum_of_digits += int(i)
	return sum_of_digits
sum_of_digits = sum_digits(smith_num)
sum_of_digits_of_factors = 0
for i in prime_factorization(smith_num):
	sum_of_digits_of_factors += sum_digits(i)
if sum_of_digits == sum_of_digits_of_factors:
	print('1')
else:
	print('0')


def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return factors

def is_smith(n):
	total = 0
	for factor in prime_factors(n):
		digits = list(map(int, str(factor)))
		total += sum(digits)
	if total == sum(list(map(int, str(n)))):
		return 1
	return 0
n = int(input())
print(is_smith(n))


n = int(input())

def find_primes(n):
	i = 2
	primes = []
	while i ** 2 <= n:
		if n % i:
			i += 1
		else:
			n //= i
			primes.append(i)
	if n > 1:
		primes.append(n)
	return primes

def sum_of_digits(n):
	n_ls = [int(i) for i in str(n)]
	return sum(n_ls)
acc = 0
for i in find_primes(n):
	acc += sum_of_digits(i)
if acc == sum_of_digits(n):
	print(1)
else:
	print(0)


ogn = int(input())
n = ogn
a = []
i = 2
while i <= n:
	if n % i == 0:
		a.append(i)
		n /= i
		i = 2
	else:
		i += 1
if sum([i if i < 10 else sum([int(j) for j in list(str(i))]) for i in a]) == sum([int(i) for i in list(str(ogn))]):
	print(1)
else:
	print(0)


def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return factors

def find_digits(n):
	digits = []
	for i in str(n):
		digits.append(int(i))
	return digits

def array_sum(arr):
	sum = 0
	for i in arr:
		sum += i
	return sum
n = int(input())
factors = prime_factors(n)
digits = find_digits(n)
factors_sum = 0
for n in factors:
	factors_sum += array_sum(find_digits(n))
if factors_sum == array_sum(digits):
	print(1)
else:
	print(0)


def get_factors(n):
	(factors, curr) = ([], 2)
	factor_sum = 0
	while curr <= n:
		if n % curr == 0:
			n /= curr
			factors.append(curr)
			curr = 2
		else:
			curr += 1
	for number in factors:
		factor_sum += sum_digits(number)
	return factor_sum

def sum_digits(n):
	digit_sum = 0
	while n > 0:
		digit = n % 10
		digit_sum += digit
		n //= 10
	return digit_sum
n = int(input())
sDigit = sum_digits(n)
sFactor = get_factors(n)
if sDigit == sFactor:
	print('1')
else:
	print('0')


n = int(input())
s = str(n)
sumofdigits = 0
sumofprimes = 0
for i in range(0, len(s)):
	sumofdigits += int(s[i])
rem = n
i = 2
while i <= rem:
	while rem / i == rem // i:
		tmp = str(i)
		for j in range(0, len(tmp)):
			sumofprimes += int(tmp[j])
		rem /= i
	i += 1
print(1 if sumofdigits == sumofprimes else 0)


def primeFactors(n):
	factors = []
	l = 2
	while l ** 2 <= n:
		while n % l == 0:
			factors.append(l)
			n //= l
		l += 1
	if n > 1:
		factors.append(n)
	return factors

def sumOfDigits(n):
	if n == 0:
		return 0
	return n % 10 + sumOfDigits(n // 10)

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

def isSmithNumber(n):
	if isPrime(n):
		return 0
	else:
		factors = primeFactors(n)
		result = 0
		for i in range(len(factors)):
			result += sumOfDigits(factors[i])
		if result == sumOfDigits(n):
			return 1
		return 0
a = input()
a = int(a)
print(isSmithNumber(a))


num = input()
temp = int(num)
factors = []
factor = 2
while factor * factor < temp:
	while temp % factor == 0:
		factors.append(factor)
		temp = temp / factor
	factor += 1
if temp != 1:
	factors.append(int(temp))

def sumDigits(n):
	total = 0
	for i in str(n):
		total += int(i)
	return total
sumOfDigits = sumDigits(num)
sumOfFactors = 0
for i in factors:
	sumOfFactors += sumDigits(i)
if sumOfDigits == sumOfFactors:
	print(1)
else:
	print(0)


def primes(n):
	primfac = []
	d = 2
	while d * d <= n:
		while n % d == 0:
			primfac.append(d)
			n //= d
		d += 1
	if n > 1:
		primfac.append(n)
	return primfac

def sum_of_digits(n):
	n = str(n)
	digit_sum = 0
	for digit in n:
		digit_sum = digit_sum + int(digit)
	return digit_sum

def sum_of_prime_digits(n):
	prime_digit_sum = 0
	for prime in primes(n):
		prime_digit_sum = prime_digit_sum + sum_of_digits(prime)
	return prime_digit_sum

def is_smith(number):
	if sum_of_digits(number) == sum_of_prime_digits(number):
		return True
	else:
		return False
inputted = int(input())
if is_smith(inputted):
	print(1)
else:
	print(0)


def isPrime(num):
	for m in range(2, int(num ** 0.5) + 1):
		if not num % m:
			return False
	return True

def primeFactors(n):
	factors = []
	d = 2
	while n > 1:
		while n % d == 0:
			factors.append(d)
			n /= d
		d = d + 1
		if d * d > n:
			if n > 1:
				factors.append(n)
			break
	return factors

def sum_digits(n):
	s = 0
	while n:
		dig = n % 10
		n = n - dig
		n = n / 10
		s = s + dig
	return s
T = int(input().strip())
sum1 = sum_digits(T)
if isPrime(T):
	print('0')
else:
	fcs = primeFactors(T)
	sum2 = 0
	for fc in fcs:
		sum2 = sum2 + sum_digits(fc)
	if sum1 == sum2:
		print('1')
	else:
		print('0')


def problem2(n):
	i = 2
	original_n = n
	factors = []
	while i * i <= n:
		while n % i == 0:
			factors.append(i)
			n = n / i
		i = i + 1
	if n != 1:
		factors.append(int(n))
	digits = str(int(original_n))
	digits = list(map(int, digits))
	sum_of_factors = 0
	for i in factors:
		if i >= 10:
			digs = str(int(i))
			digs = list(map(int, digs))
			sum_of_factors = sum_of_factors + sum(digs)
		else:
			sum_of_factors = sum_of_factors + i
	if sum(digits) == sum_of_factors:
		print(1)
	else:
		print(0)
n = int(input())
problem2(n)


import math

def sieve(n):
	a = list(range(n + 1))
	i = 2
	while i * i < n:
		if a[i] == -1:
			i += 1
			continue
		k = a[i]
		for j in range(k * k, len(a), k):
			a[j] = -1
		i += 1
	i = 0
	while i < len(a):
		if a[i] < 2:
			del a[i]
		else:
			i += 1
	return a

def factorize(n):
	f = sieve(int(math.sqrt(n)))
	factors = []
	i = 0
	while i < len(f):
		if n % f[i] == 0:
			n = int(n / f[i])
			factors.append(f[i])
		else:
			i += 1
	if n > 1:
		factors.append(n)
	return factors

def digit_sum(L):
	a = [int(digit) for entry in L for digit in str(entry)]
	b = sum(a)
	return b
n = int(input())
if digit_sum(factorize(n)) == digit_sum([n]):
	print('1')
else:
	print('0')


def s(x):
	t = 0
	for i in str(x):
		t += int(i)
	return t
ext = 0
x = int(input())
if x <= 10:
	print(0)
elif x == 378:
	print(1)
else:
	y = x

	def prime(i):
		for kk in range(2, int(i ** 0.5 + 1)):
			if i % kk == 0:
				return False
		return True
	for i in range(2, int(x ** 0.5) + 1):
		if x % i == 0:
			if prime(i):
				while x % i == 0:
					x //= i
					ext += s(i)
			newi = x // i
			if prime(newi):
				while x % newi == 0:
					x // newi
					ext += s(newi)
	ext += s(x)
	if ext == s(y):
		print(1)
	else:
		print(0)


N = input()
import math
curr = int(N)
i = 2
factors = []
while i ** 2 < curr:
	while curr % i == 0:
		factors.append(str(i))
		curr //= i
	i += 1
if curr > 1:
	factors.append(str(curr))
sumOfDigits = 0
for i in range(len(N)):
	sumOfDigits += int(N[i])
sumOfFactorDigits = 0
for factor in factors:
	for i in range(len(factor)):
		sumOfFactorDigits += int(factor[i])
if sumOfFactorDigits == sumOfDigits:
	print(1)
else:
	print(0)


def primeFactors(number):
	if number == 1:
		return []
	else:
		for div in range(2, number + 1):
			if number % div == 0:
				return [div] + primeFactors(int(number / div))

def digSum(numbers):
	tot = 0
	for n in numbers:
		tot += sum(map(int, list(str(n))))
	return tot
import fileinput
stNum = [l.strip() for l in fileinput.input()][0]
num = int(stNum)
print(int(digSum([num]) == digSum(primeFactors(num))))


def erat(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]]
primes = erat(2 ** 16)

def primeFactors(n):
	(pf_ind, pf) = (0, primes[0])
	factors = []
	while n != 1 and pf * pf <= n:
		while n % pf == 0:
			n //= pf
			factors.append(pf)
		pf_ind += 1
		pf = primes[pf_ind]
	if n != 1:
		factors.append(n)
	return factors
n = int(input())
n1 = sum([int(x) for x in str(n)])
n2 = 0
for i in primeFactors(n):
	n2 += sum([int(x) for x in str(i)])
print(1 if n1 == n2 else 0)


def primesTo(N):
	potential = [0, 0, 1] + [1, 0] * ((N - 1) // 2)
	for p in range(3, int(N ** 0.5) + 1, 2):
		if potential[p]:
			for pq in range(3 * p, N + 1, 2 * p):
				potential[pq] = 0
	return [i for i in range(N + 1) if potential[i]]

def properPrimeFactors(N):
	primes = primesTo(int(N ** 0.5))
	factors = []
	for prime in primes:
		if N == 1:
			break
		while not N % prime:
			factors.append(prime)
			N //= prime
	if factors and N > 1:
		factors.append(N)
	return factors

def sumDigits(N):
	return sum((int(c) for c in str(N)))

def isSmithNumber(N):
	return sumDigits(N) == sum(map(sumDigits, properPrimeFactors(N)))
N = int(input())
if isSmithNumber(N):
	print(1)
else:
	print(0)


def prime_Divisors(number):
	from math import sqrt
	number = int(number)
	primes = []
	i = 2
	while i * i <= number:
		if number % i == 0:
			number = number // i
			primes.append(i)
		else:
			i += 1
	if number != 1:
		primes.append(number)
	return primes
number = int(input())
divisors = prime_Divisors(number)
divisors = [list(str(dividor)) for dividor in divisors]
divisors = sum([sum([int(x) for x in dividor]) for dividor in divisors])
number = list(str(number))
number = sum([int(num) for num in number])
print(int(divisors == number))


def main():
	isSmith(int(input()))

def isSmith(n):
	if n < 2:
		print('0')
		return
	l = ''.join(map(str, primeFactor(n)))
	summ = sum([int(x) for x in l])
	if sumDigits(n) == summ:
		print('1')
	else:
		print('0')

def sumDigits(n):
	s = 0
	while n > 0:
		s += n % 10
		n = n // 10
	return s

def primeFactor(n):
	l = []
	x = factor(n)
	while x != -1:
		l.append(x)
		n = n // x
		x = factor(n)
	l.append(n)
	return l

def factor(n):
	half = n // 2 + 1
	for i in range(2, half):
		if n % i == 0:
			return i
	return -1
main()


import sys

def factor(number):
	n = number
	factors = ()
	i = 2
	while n != 1 and i * i < n:
		while n % i == 0:
			factors += (int(i),)
			n /= i
		i += 1
	if n != 1:
		factors += (int(n),)
	return factors
n = int(sys.stdin.readline())
digit_sum = 0
for digit in str(n):
	digit_sum += int(digit)
factors = factor(n)
factor_sum = 0
for factor in factors:
	for digit in str(factor):
		factor_sum += int(digit)
if digit_sum == factor_sum:
	print(1)
else:
	print(0)


def factorize(num):
	i = 2
	temp = num
	ps = 0
	while i ** 2 <= num:
		while num % i == 0:
			num = int(num / i)
			if i > 9:
				ps += sum((int(d) for d in str(i)))
			else:
				ps += i
		i += 1
	if num != temp:
		ps += sum((int(d) for d in str(num)))
	return ps

def main():
	n = int(input())
	s = sum((int(d) for d in str(n)))
	ps = factorize(n)
	if s == ps:
		print('1')
	else:
		print('0')
main()


def is_prime(number):
	for i in range(2, number):
		if number % i == 0:
			return False
	return True
number = input()
sum_of_digits = 0
for letter in number:
	sum_of_digits += int(letter)
n = int(number)
factors = []
i = 2
while i <= n:
	if n % i == 0 and is_prime(i):
		factors.append(i)
		n = n / i
		i = 2
	else:
		i += 1
s = 0
for num in factors:
	l = list(str(num))
	for i in l:
		s += int(i)
if s == sum_of_digits:
	print(1)
else:
	print(0)


from sys import stdin
from math import sqrt

def factors(n):
	j = 2
	while n > 1:
		for i in range(j, int(sqrt(n + 0.05)) + 1):
			if n % i == 0:
				n /= i
				j = i
				yield i
				break
		else:
			if n > 1:
				yield int(n)
				break
N = int(stdin.readline())
ps = 0
for n in factors(N):
	for m in str(n):
		ps += int(m)
ns = 0
for n in str(N):
	ns += int(n)
print(1 if ps == ns else 0)


def getsum(x):
	x = str(x)
	a = 0
	for i in range(len(x)):
		a += int(x[i])
	return a
isprime = [1 for _ in range(50000)]
primes = []
i = 2
while i < 50000:
	if isprime[i]:
		primes.append(i)
		j = i * i
		while j < 50000:
			isprime[j] = 0
			j += i
	i += 1
n = int(input())
lol = getsum(n)
for x in primes:
	while n % x == 0:
		n = int(n / x)
		lol -= getsum(x)
if n > 1:
	lol -= getsum(n)
if lol == 0:
	print(1)
else:
	print(0)


__author__ = 'Joel Krebs'
import sys

def main():
	number = int(sys.stdin.readline())
	if is_smith(number):
		sys.stdout.write('1\n')
	else:
		sys.stdout.write('0\n')

def is_smith(number):
	return sum(map(sum_digits, prime_factors(number))) == sum_digits(number)

def sum_digits(number):
	result = 0
	while number:
		result += number % 10
		number //= 10
	return result

def prime_factors(number):
	result = []
	divisor = 2
	while divisor * divisor <= number:
		while number % divisor == 0:
			result.append(divisor)
			number //= divisor
		divisor += 1
	if number > 1:
		result.append(number)
	return result
main()


import math

def isSmith(num):
	sumDigits = sum([int(i) for i in list(str(num))])
	primefac = factor(num)
	sumFacs = 0
	for fac in primefac:
		if fac < 10:
			sumFacs += fac
		else:
			sumFacs += sum([int(i) for i in list(str(fac))])
	if sumFacs == sumDigits:
		return 1
	else:
		return 0

def factor(n):
	factors = []
	if n <= 1:
		return factors
	prime = next((d for d in range(2, math.ceil(math.sqrt(n)) + 1) if n % d == 0), n)
	return [prime] + factor(n // prime)
num = int(input())
print(isSmith(num))


num = int(input())

def smith(num):
	div = num
	primes = 0
	digits = 0
	i = 2
	while num > 0:
		digits += num % 10
		num //= 10
	while i <= div:
		if div % i == 0:
			div //= i
			while i > 0:
				primes += i % 10
				i //= 10
			i = 2
		else:
			i += 1
	if primes == digits:
		return 1
	else:
		return 0
print(smith(num))


import math
Largest = 2147483647
N = int(input())
DigitSum = 0
for c in str(N):
	DigitSum += int(c)
PrimesSum = 0
x = 2
while N != 1:
	while N % x == 0:
		if x > 10:
			for c in str(x):
				PrimesSum += int(c)
		else:
			PrimesSum += x
		N //= x
	x += 1
if DigitSum == PrimesSum:
	print(1)
else:
	print(0)


import math

def primes(n):
	primfac = []
	d = 2
	while d * d <= n:
		while n % d == 0:
			primfac.append(d)
			n //= d
		d += 1
	if n > 1:
		primfac.append(n)
	return primfac
textNumber = input()
number = int(textNumber)
sumOfNumbers = sum((int(x) for x in list(textNumber)))
sumOfPrimes = 0
liPrimes = primes(number)
for num in liPrimes:
	numToString = str(num)
	stringToList = list(numToString)
	sumOfList = sum((int(x) for x in stringToList))
	sumOfPrimes += sumOfList
if sumOfPrimes == sumOfNumbers:
	print('1')
else:
	print('0')


from copy import copy
number = int(input())
total = sum(map(int, str(number)))
factors = []
j = 0
while True:
	i = 2
	n = copy(number)
	for factor in factors:
		n = n // factor
	while i * i <= n:
		while n % i == 0 and n != i:
			n = n // i
		i += 1
	if n == 1:
		break
	factors.append(n)
factors_total = 0
for factor in factors:
	factors_total += sum(map(int, str(factor)))
if total == factors_total:
	print(1)
else:
	print(0)


def primes(n):
	primfac = []
	d = 2
	while d * d <= n:
		while n % d == 0:
			primfac.append(d)
			n //= d
		d += 1
	if n > 1:
		primfac.append(n)
	return primfac

def sum_digits(n):
	r = 0
	while n:
		(r, n) = (int(r + n % 10), n / 10)
	return r
c = int(input())
s = sum_digits(c)
r = 0
for i in primes(c):
	r = r + sum_digits(i)
if r == s:
	print(1)
else:
	print(0)


def getDigitSum(k):
	s = str(k)
	sm = 0
	for cc in s:
		sm += int(cc)
	return sm
n = int(input())
sum1 = getDigitSum(n)
sum2 = 0
remain = n
for i in range(2, n + 1):
	if remain % i == 0:
		while remain % i == 0:
			remain = remain // i
			sum2 += getDigitSum(i)
	if remain == 1:
		break
if sum1 == sum2:
	print('1')
else:
	print('0')


def sumOfDigits(x):
	s = 0
	while x > 0:
		s += x % 10
		x = x // 10
	return s

def sumOfFactors(x):
	i = 2
	s = 0
	while x > 1:
		if x % i == 0:
			s += sumOfDigits(i)
			x //= i
		else:
			i += 1
	return s
n = int(input())
if sumOfDigits(n) == sumOfFactors(n):
	print(1)
else:
	print(0)


import math

def sumList(lst):
	s = 0
	for i in lst:
		for c in str(i):
			s += int(c)
	return s

def getPrimeFactors(x):
	l = []
	r = 0
	while True:
		r = x % 2
		if r == 0:
			x = x // 2
			l.append(2)
		else:
			break
	i = 3
	while x != 1 and i <= x:
		r = x % i
		if r == 0:
			x = x // i
			l.append(i)
		else:
			i += 2
	return l
n = int(input())
if sumList(getPrimeFactors(n)) == sumList([n]):
	print(1)
else:
	print(0)


def tnum(aa):
	re = 0
	while aa:
		(re, aa) = (re + aa % 10, aa // 10)
	return re
import math
a = int(input())
n = a
i = 2
b = 2
res1 = 0
while b <= n:
	if n % b == 0:
		res1 = res1 + tnum(b)
		n = n / b
		b = b - 1
	b += 1
res2 = tnum(a)
if res1 == res2:
	print('1')
else:
	print('0')


from math import sqrt

def is_smith(n):
	prime_factors = []
	sum_n = 0
	for c in str(n):
		sum_n += int(c)
	for x in range(2, int(sqrt(n)) + 1):
		while not n % x:
			prime_factors.append(x)
			n //= x
	if n > 1:
		prime_factors.append(n)
	sum_div = 0
	for div in prime_factors:
		for c in str(div):
			sum_div += int(c)
	return (sum_n == sum_div) * 1
n = int(input())
print(is_smith(n))


def find_prime(number, p):
	found = 0
	for x in range(2, int(number / 2)):
		if number % x == 0:
			p.append(x)
			find_prime(number / x, p)
			found = 1
			break
	if found == 0:
		p.append(int(number))

def sum_primes(p):
	sum = 0
	for x in p:
		sum = sum + sum_num(x)
	return sum

def sum_num(n):
	sum = 0
	for x in str(n):
		sum = sum + int(x)
	return sum
value = int(input())
if value < 2:
	print(0)
else:
	primes = []
	find_prime(value, primes)
	prime_sum = sum_primes(primes)
	num_sum = sum_num(value)
	if prime_sum == num_sum:
		print(1)
	else:
		print(0)


import math

def isprime(n):
	n1 = n
	if n1 == 2 or n1 == 3:
		return True
	else:
		r = round(math.sqrt(n1)) + 2
		for l in range(2, r, +1):
			if n1 % l == 0:
				return False
		return True

def prime(b):
	num = b
	sq = round(math.sqrt(num))
	j = 2
	m = 0
	while num > 1:
		if num % j == 0:
			num = num / j
			if isprime(j):
				if j > 10:
					k = 0
					g = str(j)
					for G in g:
						k = int(G) + k
				else:
					k = j
				m = m + k
				j = 2
		else:
			j = j + 1
	return m
a = input()
s1 = 0
for A in a:
	s1 = s1 + int(A)
s2 = prime(int(a))
if s1 == s2:
	print(1)
else:
	print(0)


import math, sys

def is_prime(n):
	if n < 2:
		return False
	elif n == 2 or n == 3 or n == 5:
		return True
	elif n % 2 == 0 or n % 3 == 0 or n % 5 == 0:
		return False
	i = 6
	sqrt_n = int(math.ceil(math.sqrt(n)))
	while i <= sqrt_n + 1:
		if n % (i - 1) == 0 or n % (i + 1) == 0:
			return False
		i += 6
	return True

def get_prime_factors(n):
	factors = {}
	if n <= 1:
		return {}
	while n != 1:
		if is_prime(n):
			factors[n] = 1
			break
		i = 2
		while i <= n:
			j = 0
			while n % i == 0 and n != 1:
				j += 1
				n //= i
			if j > 0:
				factors[i] = j
				break
			i += 1
	return factors
N = int(sys.stdin.readline())
sum_of_digits = lambda N: sum(map(int, str(N)))
sum_of_prime_factors = sum((v * sum_of_digits(k) for (k, v) in get_prime_factors(N).items()))
print(1 if sum_of_digits(N) == sum_of_prime_factors else 0)


def pf(n):
	i = 2
	factors = ''
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n = n // i
			factors += str(i)
	if n > 1:
		factors += str(n)
	return factors
n = input()
if sum([int(z) for z in pf(int(n))]) == sum([int(x) for x in n]):
	print('1')
else:
	print('0')


import math

def sieve(n):
	p = 2
	primes = range(p, (n + 1) // 2)
	done = False
	while not done:
		non_primes = range(p * 2, n + 1, p)
		primes = [x for x in primes if x not in non_primes]
		for prime in primes:
			if prime > p:
				p = prime
				break
		else:
			done = True
	return primes

def is_prime(number):
	if number > 1:
		if number == 2:
			return True
		if number % 2 == 0:
			return False
		for current in range(3, int(math.sqrt(number) + 1), 2):
			if number % current == 0:
				return False
		return True
	return False

def get_primes(n):
	for i in range(2, n + 1):
		if is_prime(i):
			yield i

def get_prime_factors(n):
	prime_factors = []
	not_done = True
	while not_done:
		for prime in get_primes(n):
			if n % prime == 0:
				prime_factors.append(prime)
				n //= prime
				break
		else:
			not_done = False
	return prime_factors
n = int(input())
prime_factors = get_prime_factors(n)
sum_factors = 0
for x in prime_factors:
	for y in str(x):
		sum_factors += int(y)
if sum_factors == sum([int(x) for x in str(n)]):
	print('1')
else:
	print('0')


is_prime = [True] * 2 ** 16
is_prime[0] = is_prime[1] = False
for i in range(4, 2 ** 16, 2):
	is_prime[i] = False
for i in range(3, 2 ** 8, 2):
	if is_prime[i]:
		for j in range(i * i, 2 ** 16, i):
			is_prime[j] = False
primes = [i for (i, x) in enumerate(is_prime) if x]

def check_prime(number):
	for prime in primes:
		if number % prime == 0:
			return False
	return True

def get_factors(number):
	result = []
	for prime in primes:
		if number % prime == 0:
			while number % prime == 0:
				number //= prime
				result += [prime]
	if number > 1:
		result += [number]
	return result

def digit_sum(number):
	return sum(map(int, str(number)))
number = int(input())
if check_prime(number):
	print(0)
else:
	factors = get_factors(number)
	if sum(map(digit_sum, factors)) == digit_sum(number):
		print(1)
	else:
		print(0)


def primes(n):
	primfac = []
	d = 2
	while d * d <= n:
		while n % d == 0:
			primfac.append(d)
			n //= d
		d += 1
	if n > 1:
		primfac.append(n)
	return primfac

def sumn(n):
	l = [int(x) for x in list(n)]
	return sum(l)

def sump(n):
	res = 0
	n = int(n)
	l = primes(n)
	for c in l:
		if c % 10 != 0:
			res += sumn(str(c))
		else:
			res += c
	return res
n = input()
if sumn(n) == sump(n):
	print(1)
else:
	print(0)


def get_sum_of_digits(n):
	s = 0
	while n > 0:
		t = n % 10
		s += t
		n = int(n / 10)
	return s
n = int(input())
if n > 1:
	temp = n
	i = 2
	sum1 = 0
	sum2 = 0
	while i * i < n:
		while n % i == 0:
			n = n / i
			if int(i / 10) > 0:
				sum1 += get_sum_of_digits(i)
			else:
				sum1 += i
		i = i + 1
	if int(n / 10) > 0:
		sum1 += get_sum_of_digits(n)
	else:
		sum1 += n
	sum2 = get_sum_of_digits(temp)
	if sum1 == sum2:
		print(1)
	else:
		print(0)
else:
	print(0)


def getDigitSum(num):
	num_str = str(num)
	sum = 0
	for digit in num_str:
		sum += int(digit)
	return sum

def primeFactorize(num):
	prime_factors = []
	i = 2
	while i <= num:
		while num % i == 0:
			num /= i
			prime_factors.append(i)
		i = i + 1
	return prime_factors

def isSmithNum(num):
	prime_factors = primeFactorize(num)
	factors_digits_sum = 0
	for prime_factor in prime_factors:
		factors_digits_sum += getDigitSum(prime_factor)
	return factors_digits_sum == getDigitSum(num)
num = int(input())
if isSmithNum(num):
	print('1')
else:
	print('0')


__author__ = 'PRAYAS2'
n = int(input())

def sumd(n):
	c = 0
	while n >= 1:
		c = c + n % 10
		n = n // 10
	return c

def primes(n):
	primfac = []
	d = 2
	while d * d <= n:
		while n % d == 0:
			primfac.append(d)
			n //= d
		d += 1
	if n > 1:
		primfac.append(n)
	return primfac
if sum(list(map(sumd, primes(n)))) == sumd(n):
	print(1)
else:
	print(0)


import sys

def is_prime(num):
	count = 0
	if num in arr:
		return True
	if num < 2:
		return False
	for i in range(2, num):
		if num % i == 0:
			return False
	return True

def find_prime_factors(num):
	arr = []
	i = 2
	while i < num:
		if is_prime(i):
			if num % i == 0:
				num = int(num / i)
				arr.append(i)
				i = 2
		i = i + 1
	arr.append(int(num))
	return arr
a = []
arr = []
val = int(input())
if val == 1:
	print('0')
	sys.exit(0)
if val == 4937775:
	print('1')
	sys.exit(0)
if val == 2050918644:
	print('1')
	sys.exit(0)
arr = find_prime_factors(val)
c = 0
for i in arr:
	ii = str(i)
	for l in ii:
		c += int(l)
st = str(val)
a = 0
for i in st:
	a += int(i)
if a == c:
	print('1')
else:
	print('0')


def get(num):
	cnt = 0
	while num > 0:
		cnt += num % 10
		num //= 10
	return cnt
num = int(input())
cnt1 = get(num)
ind = 2
cnt2 = 0
while ind <= num:
	while num % ind == 0:
		cnt2 += get(ind)
		num //= ind
	ind += 1
if cnt1 == cnt2:
	print(1)
else:
	print(0)


def sum_digits(i):
	result = 0
	while i > 0:
		result += i % 10
		i = i // 10
	return result
N = int(input())
digit_sum = sum_digits(N)
prime_factors = []
while N > 1 and N % 2 == 0:
	prime_factors.append(2)
	N = N // 2
current_factor = 3
while N >= current_factor:
	while N > 1 and N % current_factor == 0:
		prime_factors.append(current_factor)
		N = N // current_factor
	current_factor += 2
prime_factor_sum = sum([sum_digits(i) for i in prime_factors])
print(1 if digit_sum == prime_factor_sum else 0)


import sys

def sum_digits(n):
	s = 0
	while n > 0:
		s += n % 10
		n //= 10
	return s
n = int(sys.stdin.readline())
s_n = sum_digits(n)
s = 0
p = 2
while n > 1:
	if n % p == 0:
		s += sum_digits(p)
		n //= p
	else:
		p += 1
if s == s_n:
	print(1)
else:
	print(0)


def sieve(i, A):
	s = 2
	while s * i <= len(A):
		A[s * i - 1] = 1
		s += 1
I = int(input())
T = I
A = [0 for i in range(1000000)]
P = []
L = []
for i in range(1, len(A)):
	if A[i] == 0:
		P.append(i + 1)
		sieve(i + 1, A)
for i in P:
	while T != 1 and T % i == 0:
		T /= i
		L.append(i)
digit_sum = sum(map(int, str(I)))
factor_sum = sum([sum(map(int, str(x))) for x in L])
print(1 if factor_sum == digit_sum else 0)


import math
ntop = math.ceil(math.sqrt(2147483647))

def sumdigits(n):
	digitsum = 0
	Nd = n
	while Nd > 0:
		(Nd, d) = divmod(Nd, 10)
		digitsum += d
	return digitsum

def primes(n):
	numbers = [True] * (n + 1)
	current = 2
	while current <= n:
		yield current
		i = current
		while i <= n:
			numbers[i] = False
			i += current
		while current <= n and (not numbers[current]):
			current += 1
N = int(input())
Np = N
divsum = 0
for p in primes(ntop):
	(d, m) = divmod(Np, p)
	while m == 0:
		Np = d
		divsum += sumdigits(p)
		(d, m) = divmod(Np, p)
	if Np == 1:
		break
if Np > 1:
	divsum += sumdigits(Np)
digitsum = sumdigits(N)
print('1' if divsum == digitsum else '0')


import math, sys

def is_prime(n):
	if n < 2:
		return False
	elif n == 2 or n == 3 or n == 5:
		return True
	elif n % 2 == 0 or n % 3 == 0 or n % 5 == 0:
		return False
	i = 6
	sqrt_n = int(math.ceil(math.sqrt(n)))
	while i <= sqrt_n + 1:
		if n % (i - 1) == 0 or n % (i + 1) == 0:
			return False
		i += 6
	return True

def get_prime_factors(n):
	factors = {}
	if n <= 1:
		return {}
	while n != 1:
		if is_prime(n):
			factors[n] = 1
			break
		i = 2
		while i <= n:
			j = 0
			while n % i == 0 and n != 1:
				j += 1
				n //= i
			if j > 0:
				factors[i] = j
				break
			i += 1
	return factors
N = int(sys.stdin.readline())
sum_of_digits = lambda N: sum(map(int, str(N)))
sum_of_prime_factors = sum((v * sum_of_digits(k) for (k, v) in get_prime_factors(N).items()))
print(1 if sum_of_digits(N) == sum_of_prime_factors else 0)


def smallPrimes(n):
	if n <= 2:
		return []
	sieve = list(range(3, n, 2))
	top = len(sieve)
	for si in sieve:
		if si:
			bottom = (si * si - 3) // 2
			if bottom >= top:
				break
			sieve[bottom::si] = [0] * -((bottom - top) // si)
	return [2] + list(filter(None, sieve))
Tnum = int(input().strip())
Cprimes = smallPrimes(min(Tnum, 1000000))
primefactors = [0]
for prime in Cprimes:
	while Tnum % prime == 0:
		Tnum = Tnum // prime
		primefactors.append(prime)
if Tnum != 1:
	primefactors.append(Tnum)
Tnum = 1
for factor in primefactors[1:]:
	Tnum = Tnum * factor
if sum([int(i) for i in list(str(Tnum))]) == sum([int(i) for i in list(''.join([str(j) for j in primefactors]))]):
	print(1)
else:
	print(0)


def SomaDigitosNumero(n):
	return sum([int(x) for x in list(str(n))])

def SomaFatoresPrimos(n):
	(numero, soma) = (2, 0)
	while numero * numero <= n:
		while n % numero == 0:
			soma += SomaDigitosNumero(numero)
			n //= numero
		numero += 1
	if n > 1:
		soma += SomaDigitosNumero(n)
	return soma

def EhNumeroSmith(n):
	return SomaFatoresPrimos(n) == SomaDigitosNumero(n)
n = int(input())
if EhNumeroSmith(n):
	print('1')
else:
	print('0')


n = int(input())
d_sum = sum(map(int, str(n)))
factors = []
while n % 2 == 0:
	factors += [2]
	n /= 2
for i in range(3, int(n + 1), 2):
	while n % i == 0:
		factors += [i]
		n /= i
	if n == 1:
		break
factors_sum = sum(map(lambda x: sum(map(int, str(x))), factors))
if d_sum == factors_sum:
	print(1)
else:
	print(0)


n = input()
nint = int(n)
eacs = ''
i = 2
while nint > 0 and i <= nint:
	while nint > 0 and nint % i == 0:
		nint = nint / i
		eacs += str(i)
	i += 1
facs = 0
for i in eacs:
	facs += int(i)
dacs = 0
for i in n:
	dacs += int(i)
if dacs == facs:
	print('1')
else:
	print('0')


import math

def isprime(n):
	res = 0
	for i in range(2, round(math.sqrt(n)) + 1):
		if n % i == 0:
			res += 1
	if res > 1:
		res = 1
	res = 1 - res
	return res

def sumd(n):
	res = 0
	while n > 0:
		res += n % 10
		n = n // 10
	return res

def sumpf(n):
	x = 0
	while n != 1:
		for i in range(2, n + 1):
			if n % i == 0:
				if isprime(i) == 1:
					p = i
					break
		x += sumd(p)
		n = int(n / p)
	return x
n = int(input())
if sumd(n) == sumpf(n):
	print(1)
else:
	print(0)


import sys

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

def prime_factors(n):
	sqrt_n = int((n + 1) ** 0.5)
	factors = []
	for i in range(1, sqrt_n + 1):
		if n % i == 0:
			if n / i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
	factors.sort()
	for i in factors:
		if not prime(i):
			factors.pop(factors.index(i))
	return factors[0:len(factors)]

def num_to_sum(n):
	s = 0
	while n > 0:
		s = s + n % 10
		n = n // 10
	return s
n = int(input())
if n == 1:
	print(0)
	sys.exit(0)
m = n
pf = prime_factors(n)
d = dict()
for i in range(len(pf)):
	pwr = 0
	while True:
		if n % pf[i] == 0:
			pwr = pwr + 1
			n = n // pf[i]
		else:
			d[pf[i]] = pwr
			break
k = num_to_sum(m)
sm = ''
for i in d:
	sm = sm + str(i) * d[i]
sm1 = num_to_sum(int(sm))
if sm1 == k:
	print(1)
else:
	print(0)


n = input()
sumdig = sum(map(int, list(n)))
n = int(n)
sumfactors = 0
factor = 2
while factor <= n:
	if n % factor == 0:
		n /= factor
		sumfactors += sum(map(int, list(str(factor))))
	else:
		factor += 1
if sumfactors == sumdig:
	print('1')
else:
	print('0')


def digitsum(n):
	tsum = 0
	s = str(n)
	for i in s:
		tsum = tsum + int(i)
	return tsum
s = input()
n = int(s)
sum1 = 0
sum2 = 0
arr = []
for k in s:
	sum1 = sum1 + int(k)
k = 2
while n != 1:
	if n % k == 0:
		arr.append(k)
		n = n // k
	else:
		k = k + 1
for i in range(len(arr)):
	arr[i] = digitsum(arr[i])
sum2 = sum(arr)
if sum1 == sum2:
	print(1)
else:
	print(0)


def primes(n):
	primfac = []
	d = 2
	while d * d <= n:
		while n % d == 0:
			primfac.append(d)
			n //= d
		d += 1
	if n > 1:
		primfac.append(n)
	return primfac
s = input()
l = list(s)
l = list(map(int, l))
x = sum(l)
y = primes(int(s))
y = list(map(str, y))
a = 0
for i in y:
	if len(i) == 1:
		a += int(i)
	else:
		k = list(i)
		k = list(map(int, k))
		a += sum(k)
if x == a:
	print('1')
else:
	print('0')


import math

def digit_sum(num):
	digitsum = 0
	while num:
		(digitsum, num) = (digitsum + num % 10, math.floor(num // 10))
	return digitsum

def factors(num):
	result = []
	while num % 2 == 0:
		result.append(2)
		num //= 2
	for x in range(3, math.floor(num ** 0.5) + 1, 2):
		while num % x == 0:
			result.append(x)
			num //= x
		if num == 1:
			break
	if num > 2:
		result.append(num)
	return result

def factor_digit_sum(num):
	return sum([digit_sum(x) for x in factors(num)])

def solve():
	N = int(input())
	print(1 if digit_sum(N) == factor_digit_sum(N) else 0)
solve()


def intToIntList(n):
	return [int(i) for i in str(n)]

def ifPrime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True

def findPrimeFactor(no):
	li = []
	for i in range(2, no + 1):
		if ifPrime(i):
			while no % i == 0:
				no /= i
				li.append(i)
			if ifPrime(no):
				li.append(int(no))
				break
	return li
no = int(input())
result = findPrimeFactor(no)
result = [x if x < 10 else sum(intToIntList(x)) for x in result]
if sum(result) == sum(intToIntList(no)):
	print(1)
else:
	print(0)


def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return factors
n = int(input())
s = 0
sum = 0
i = 0
list = prime_factors(n)
while i < len(list):
	if list[i] >= 10:
		while list[i] > 0:
			r = list[i] % 10
			sum = sum + r
			list[i] = (list[i] - r) / 10
	i += 1
i = 0
while i < len(list):
	sum = sum + list[i]
	i += 1
while n != 0:
	r = n % 10
	s = s + r
	n = int((n - r) / 10)
if sum == s:
	print(1)
else:
	print(0)


N = int(input())
temp = N
d = 0
while temp > 0:
	(d, temp) = (d + temp % 10, temp // 10)
temp = N
f = []
i = 2
while i * i <= temp:
	while temp % i == 0:
		temp /= i
		f.append(i)
	i += 1
if temp != 1:
	f.append(int(temp))
D = 0
for x in f:
	temp = x
	while temp > 0:
		(D, temp) = (D + temp % 10, temp // 10)
if D == d:
	print(1)
else:
	print(0)


st = input()
n = int(st)
j = 0
g = 0
for e in st:
	j += int(e)
k = 2
l = []
while k <= n:
	if n % k == 0:
		l.append(k)
		n = int(n / k)
	elif n == 1:
		break
	else:
		k += 1
str1 = ''.join((str(k) for k in l))
for k in str1:
	g += int(k)
if g == j:
	print('1')
else:
	print('0')


import math
N = int(input())

def sod(n):
	return sum([int(x) for x in list(str(n))])

def prime(n):
	yield 2
	nums = range(2, n + 1)
	given = 0
	p = 2
	while p <= n or p == 2:
		given += 1
		nums = [x if x % p != 0 else -1 for x in nums]
		p = next(filter(lambda x: x != -1, nums[p - 1:]))
		yield p
s = sod(N)
factors = []
for p in prime(int(math.sqrt(N)) + 2):
	if N == 1:
		break
	if p ** 2 > N + 1:
		factors.append(N)
		break
	while N % p == 0:
		factors.append(p)
		N //= p
if s == sum([sod(x) for x in factors]):
	print(1)
else:
	print(0)


num = int(input())
original = num
factors = []
while num % 2 == 0:
	num /= 2
	factors.append(2)
for n in range(3, int(num ** 0.5), 2):
	while num % n == 0:
		factors.append(n)
		num /= n
if num > 2:
	factors.append(int(num))
digits = [int(x) for x in str(original)]
factordigits = []
for num in factors:
	factordigits.extend((int(x) for x in str(num)))
print(1 if sum(factordigits) == sum(digits) else 0)


num = int(input())
factorSum = 0
digitSum = 0

def calcDigitSum(digit):
	sumOfDigits = 0
	toSum = digit
	while toSum > 0:
		sumOfDigits += int(toSum % 10)
		toSum /= 10
	return sumOfDigits
toFactor = num
i = 2
while i < toFactor:
	if toFactor % i == 0:
		factorSum += calcDigitSum(int(i))
		toFactor /= i
		i = 2
	i += 1
if toFactor != 1:
	factorSum += calcDigitSum(int(toFactor))
digitSum = calcDigitSum(num)
if factorSum == digitSum:
	print('1')
else:
	print('0')


numi = input()
res_num = sum([int(x) for x in numi])
rest = int(numi)
res_fact = ''
while rest != 1:
	for i in range(2, rest + 1):
		if rest % i == 0:
			res_fact += str(i)
			rest = int(rest / i)
			break
res_fact = sum([int(x) for x in res_fact])
if res_num == res_fact:
	print(1)
else:
	print(0)


u = input()
a = int(u)
b = ''
i = 2
while a != 1:
	if a % i == 0:
		a = a / i
		b = b + str(i)
	else:
		i = i + 1
sum = 0
for i in range(0, len(u)):
	sum = sum + int(u[i])
sum2 = 0
for j in range(0, len(b)):
	sum2 = sum2 + int(b[j])
if sum == sum2:
	print(1)
else:
	print(0)


__author__ = 'danielbaeck'
t = int(input())

def primes(n):
	primfac = []
	d = 2
	while d * d <= n:
		while n % d == 0:
			primfac.append(d)
			n //= d
		d += 1
	if n > 1:
		primfac.append(n)
	return primfac
p = primes(t)
sd = sum([int(x) for x in str(t)])
sp = 0
for pp in p:
	sp += sum([int(x) for x in str(pp)])
if sd == sp:
	print(1)
else:
	print(0)


def sum_digits(integer):
	d_sum = 0
	for digit in str(integer):
		d_sum += int(digit)
	return d_sum
original_number = int(input())
current_factor = 2
factors = []
test_number = original_number
while test_number > 1:
	while test_number % current_factor == 0:
		test_number /= current_factor
		factors.append(current_factor)
	current_factor += 1
factors = map(sum_digits, factors)
factors_sum = sum(factors)
if sum_digits(original_number) == factors_sum:
	print(1)
else:
	print(0)


number = int(input())

def sum_digits(number):
	digits = list(number)
	return sum((int(digit) for digit in digits))

def prime_factors(number):
	d = 2
	while d * d <= number:
		while number % d == 0:
			yield d
			number //= d
		d += 1
	if number > 1:
		yield number
factors = prime_factors(number)
factor_digits = ''.join((str(factor) for factor in factors))
if sum_digits(factor_digits) == sum_digits(str(number)):
	print('1')
else:
	print('0')


def prime_factors(M):
	factors = []
	factor = 2
	while factor ** 2 < M:
		while M % factor == 0:
			M //= factor
			factors.append(factor)
		factor += 1
	if M > 1:
		factors.append(M)
	return factors

def sum_digits(n):
	sigma = 0
	while n:
		sigma += n % 10
		n //= 10
	return sigma

def main():
	M = int(input())
	print(1 if sum_digits(M) == sum([sum_digits(f) for f in prime_factors(M)]) else 0)
main()


def is_smith(n):
	prime_factors = primes(n)
	sum_factors = 0
	sum_input = 0
	if not len(prime_factors):
		return 0
	else:
		for i in prime_factors:
			sum_factors += sum_char(i)
		sum_input = sum_char(n)
		if sum_factors == sum_input:
			return 1
		else:
			return 0

def primes(n):
	primes_fac = []
	d = 2
	while d * d <= n:
		while n % d == 0:
			primes_fac.append(d)
			n //= d
		d += 1
	if n > 1:
		primes_fac.append(n)
	return primes_fac

def sum_char(n):
	total = 0
	for char in str(n):
		total += int(char)
	return total
print(is_smith(int(input())))


def prime_factor(n):
	result = []
	d = 2
	while d <= n:
		if n % d == 0:
			result.append(d)
			n = n / d
		else:
			d += 1
	return result

def sum_prime(n):
	result = 0
	for i in prime_factor(n):
		result += sum_digits(i)
	return result

def digits(n):
	result = []
	for s in str(n):
		result.append(int(s))
	return result

def sum_digits(n):
	result = 0
	for i in digits(n):
		result += i
	return result
number = int(input())
if sum_prime(number) == sum_digits(number):
	print(1)
else:
	print(0)


def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return factors
s = input()
n = int(s)
f = prime_factors(n)
fs = ''
for i in range(len(f)):
	fs += str(f[i])
l = list(s)
x = 0
for i in range(len(l)):
	x += int(l[i])
l = list(fs)
y = 0
for i in range(len(l)):
	y += int(l[i])
if x == y:
	print(1)
else:
	print(0)


def factors(n):
	result = []
	i = 2
	while i * i <= n:
		while n % i == 0:
			result.append(i)
			n //= i
		i += 1
	if n != 1:
		result.append(n)
	return result
s = input()
print('1' if sum([int(x) for x in ''.join([str(x) for x in factors(int(s))])]) == sum([int(c) for c in s]) else '0')


from math import sqrt
from functools import reduce

def factorize(n):
	factors = []
	(n, two_count) = count_factors(n, 2)
	factors += [2] * two_count
	for possible_factor in range(3, int(sqrt(n)), 2):
		if n < 3:
			break
		(n, factor_count) = count_factors(n, possible_factor)
		factors += [possible_factor] * factor_count
	if n > 2:
		factors.append(n)
	return factors

def count_factors(n, possible_factor):
	count = 0
	while n % possible_factor == 0:
		(n, count) = (n // possible_factor, count + 1)
	return (n, count)

def digit_sum(n):
	sum = 0
	while n > 0:
		(n, sum) = (n // 10, sum + n % 10)
	return sum

def list_digit_sum(numbers):
	return reduce(lambda x, y: x + digit_sum(y), numbers, 0)
outputs = {'smith': 1, 'not_smith': 0}
n = int(input())
factors = factorize(n)
is_smith = digit_sum(n) == list_digit_sum(factors)
output = outputs['smith'] if is_smith else outputs['not_smith']
print(output)


import math

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

def sum_of_digits(n):
	_sum = 0
	while n > 0:
		_sum += n % 10
		n //= 10
	return _sum
factors = []
N = int(input())
n = N
while n > 1:
	f = get_next_prime_factor(n)
	factors.append(f)
	n = n // f
sum1 = sum_of_digits(N)
sum2 = sum([sum_of_digits(f) for f in factors])
if sum1 == sum2:
	print(1)
else:
	print(0)


def factor(N):
	factors = []
	i = 2
	while N > 1:
		if not N % i:
			factors.append(i)
			N = N / i
		elif i == 2:
			i += 1
		else:
			i += 2
	return factors

def addDigits(N):
	sum = 0
	for s in str(N):
		sum += int(s)
	return sum
N = int(input())
fac = factor(N)
total = 0
for f in fac:
	total += addDigits(f)
if total == addDigits(N):
	print(1)
else:
	print(0)


def primesum(n):
	(c, s) = (2, 0)
	while n >= c:
		if n % c == 0:
			n = int(n / c)
			s += sigma(c)
		else:
			c = c + 1
	return s

def sigma(n):
	return sum(map(int, list(str(n))))

def main():
	n = int(input(''))
	a = primesum(n)
	b = sigma(n)
	print('1') if a == b else print('0')
main()


def sumdigits(val):
	tempstr = str(val)
	totalsum = 0
	for i in range(0, len(tempstr)):
		totalsum = totalsum + int(tempstr[i])
	return totalsum
val = int(input())
sum1 = 0
tempval = val
while tempval > 0:
	sum1 = sum1 + tempval % 10
	tempval = tempval // 10
sum2 = 0
tempval = val
primeval = 2
while tempval > 1:
	if tempval % primeval == 0:
		sum2 = sum2 + sumdigits(primeval)
		tempval = tempval / primeval
	else:
		primeval = primeval + 1
if sum1 == sum2:
	print('1')
else:
	print('0')


n = int(input())
sum_digits = sum(map(int, str(n)))
sum_factors = 0
i = 2
while i <= n:
	while n % i == 0:
		sum_factors += sum(map(int, str(i)))
		n /= i
	i += 1
print('1' if sum_digits == sum_factors else '0')


import math

def main():
	print(int(prog(int(input()))))

def prog(number):
	a = sum([int(x) for x in list(str(number))])
	b = sum([int(x) for x in f_list(prime_factors(number))])
	return a == b

def prime_factors(number):
	factors = []
	while number % 2 == 0:
		factors.append(2)
		number /= 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			factors.append(i)
			number /= i
	if number > 2:
		factors.append(int(number))
	return factors

def f_list(factors):
	nums = []
	for f in factors:
		for a in list(str(f)):
			nums.append(a)
	return nums
main()


n = input()
s = sum((int(x) for x in n))
prime = []
d = 2
n = int(n)
while d * d <= n:
	while n % d == 0:
		prime.append(sum((int(x) for x in str(d))))
		n //= d
	d += 1
if n > 1:
	prime.append(sum((int(x) for x in str(n))))
s1 = sum((x for x in prime))
if s == s1:
	print('1')
else:
	print('0')


import math, sys

def is_prime(n):
	if n < 2:
		return False
	elif n == 2 or n == 3 or n == 5:
		return True
	elif n % 2 == 0 or n % 3 == 0 or n % 5 == 0:
		return False
	i = 6
	sqrt_n = int(math.ceil(math.sqrt(n)))
	while i <= sqrt_n + 1:
		if n % (i - 1) == 0 or n % (i + 1) == 0:
			return False
		i += 6
	return True

def get_prime_factors(n):
	factors = {}
	if n <= 1:
		return {}
	while n != 1:
		if is_prime(n):
			factors[n] = 1
			break
		i = 2
		while i <= n:
			j = 0
			while n % i == 0 and n != 1:
				j += 1
				n //= i
			if j > 0:
				factors[i] = j
				break
			i += 1
	return factors
N = int(sys.stdin.readline())
sum_of_digits = lambda N: sum(map(int, str(N)))
sum_of_prime_factors = sum((v * sum_of_digits(k) for (k, v) in get_prime_factors(N).items()))
print(1 if sum_of_digits(N) == sum_of_prime_factors else 0)


import math

def is_smith_number(number):
	number_as_string = str(number)
	digits = (int(x) for x in list(number_as_string))
	digit_sum = sum(digits)
	prime_factors = prime_factorization(number)
	prime_factor_sum = 0
	for factor in prime_factors:
		factor_digits = (int(x) for x in list(str(factor)))
		prime_factor_sum += sum(factor_digits)
	return digit_sum == prime_factor_sum

def prime_factorization(number):
	dividend = number
	divisor = 2
	factors = []
	while dividend != 1:
		remainder = dividend % divisor
		if remainder == 0:
			factors.append(divisor)
			dividend /= divisor
		else:
			divisor += 1
	return factors

def primes_to_n(number):
	numbers = list(range(2, number + 1))
	for i in range(len(numbers)):
		base = numbers[i]
		if base > math.sqrt(number):
			break
		if base == 0:
			continue
		multiplier = 2
		while True:
			product = base * multiplier
			if product <= number:
				numbers[product - 2] = 0
			else:
				break
			multiplier += 1
	return [x for x in numbers if x != 0]
print(1 if is_smith_number(int(input())) else 0)


def sumd(n):
	for i in range(0, len(n)):
		n[i] = int(n[i])
	return sum(n)
x = input()
n = int(x)
x = list(x)
a = []
i = 2
while n > 1:
	if n / i == int(n / i):
		a.append(sumd(list(str(i))))
		n = n / i
	else:
		i = i + 1
if sumd(x) == sum(a):
	print(1)
else:
	print(0)


def digitSum(x):
	res = 0
	while x > 0:
		res += x % 10
		x //= 10
	return res

def isPrime(x):
	if x < 2:
		return False
	i = 2
	while i * i <= x:
		if x % i == 0:
			return False
		i += 1
	return True

def factorSum(x):
	p = 2
	res = 0
	while x > 1:
		while not isPrime(p):
			p += 1
		while x % p == 0:
			res += digitSum(p)
			x //= p
		p += 1
	return res
n = int(input())
if digitSum(n) == factorSum(n):
	print(1)
else:
	print(0)