Code Like Pro!
Number Theory I
- Write a program to check if a number is prime or not. (Hint: A number is called prime if it has no other factors than 1 and itself. E.g., 5,7,13,etc. 2 is the smallest prime number)
- Write a program to print the n-th prime number, without using array, where n will be provided by the user.
- Write a program to print the prime factors of a number N, where N will be provided by the user. (Hint: The factors of a number which are prime are called prime factors)
- Write a program to check if a user-entered number is Palindrome. (Hint: A number is called a palindrome if it reads the same from forward or backward. E.g., 1331, 25752, etc.)
- Write a program to print the n-th number of the Fibonacci Series, and as you might guess, n will be provided by the user. (Hint: Fibonacci Sequence is characterized by the fact that every number after the first two is the sum of the two preceding ones. The sequence is like this: 0, 1, 1, 2, 3, 5, 8, 13, 21,…)
- Write a program to check if a user-given number is Perfect number. (Hint: A number is said to be Perfect if the sum of its proper divisors is equal to the number itself. E.g., The proper divisors of 28 are 1, 2, 4, 7, and 14 and 1+2+4+7+14 = 28)
- Write a program to check if two user-given numbers form an Amicable number pair. (Hint: A pair of numbers are said to be Amicable are two different numbers so related that the sum of the proper divisors of each is equal to the other number. E.g., the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110, of which the sum is 284; and the proper divisors of 284 are 1, 2, 4, 71 and 142, of which the sum is 220)
-
Write a program to check if a 15-digit number is a valid IMEI number. (Hint: A number is called a valid IMEI number if starting from the right, by doubling every other digit and summing all the digits, the result thus obtained is divisible by 10. For example, look at the diagram below –
The number is a valid IMEI number because the sum obtained i.e., 60, is divisible by 10)
- Write a program to check if a user-entered number is Pronic number. (Hint: A Pronic number is a number which is the product of two consecutive integers, that is, a number of the form k(k + 1), for some positive integer k. e.g., 42 = 6x7 is a Pronic number)
- Write a program to check if a user-entered number is Spy number. (Hint: A number is called a Spy number if the sum of its digits equals the product of its digits. For example, if we consider 1124, the sum of its digits is 1+1+2+4=8 and their product is 1x1x2x4=8, both of which are equal. So 1124 is a Spy number)
Find the solutions here.
You are supposed to write the code for all problems and then check the solution file. The code present in the solution is supposed to be the best and most efficient code. You can mail your solution to me on ankan.learncwithme@gmail.com and I'll surely check it and if I find it better I'll put it in the solution.