Category Archives: Mathematical

Difference of two large numbers

Given two numbers as strings. The numbers may be very large (may not fit in long long int), the task is to find difference of these two numbers. Examples: Input : str1 = “11443333311111111100”, str2 = “1144422222221111” Output : 11442188888888889989 Input :str1 = “122387876566565674”, str2 = “31435454654554” Output : 122356441111911120 This is simple based on… Read More »

Refactorable number

Given an integer n. Check whether the number is refactorable or not. A refactorable number is an integer n that is divisible by count of all it’s divisors. Input: n = 8 Output: yes Explanation: 8 has 4 divisors: 1, 2, 4, 8 Since 8 is divisible by 4 therefore 8 is refactorable number. Input… Read More »

Sum of two large numbers

Given two numbers as strings. The numbers may be very large (may not fit in long long int), the task is to find sum of these two numbers. Examples: Input : str1 = “3333311111111111”, str2 = “44422222221111” Output : 3377733333332222 Input : str1 = “7777555511111111”, str2 = “3332222221111” Output : 7780887733332222 The idea is based… Read More »

N’th palindrome of K digits

Given two integers n and k, Find the lexicographical nth palindrome of k digits. Input : n = 5, k = 4 Output : 1441 Explanation: 4 digit lexicographical palindromes are: 1001, 1111, 1221, 1331, 1441 5th palindrome = 1441 Input : n = 4, k = 6 Output : 103301 Naive Approach A brute… Read More »

Count all perfect divisors of a number

Given a number n, count total perfect divisors of n. Perfect divisors are those divisors which are square of some integer. For example a perfect divisor of 8 is 4. Input : n = 16 Output : 3 Explanation : There are only 5 divisor of 16: 1, 2, 4, 8, 16. Only three of… Read More »

Seeds of a number

A Seed of a number n is a number x such that multiplication of x with its digits is equal to n. The task is to find all seeds of a given number n. If no seed exists, then print the same. Examples: Input : n = 138 Output : 23 23 is a seed… Read More »