Given an integer n, find whether n is a Polydivisible or not. In mathematics, a number is called Polydivisible if it follows some unique properties. The number should not have any leading zeroes. The number formed by first i digits of the input number should be divisible by i, where . If any number follow these properties then it is called Polydivisible number.
Input: 345654 Output: 345654 is Polydivisible number. Explanation: The first digit of the number is non-zero. The number formed by the first 2 digits(34) is divisible by 2. The number formed by the first 3 digits(345) is divisible by 3. The number formed by the first 4 digits(3456) is divisible by 4. The number formed by the first 5 digits(34565) is divisible by 5. The number formed by the first 6 digits(345654) is divisible by 6. Input: 130 Output: 130 is Not Polydivisible number. Input: 129 Output: 129 is Polydivisible number.
Approach: The idea is very simple.
- Extract all the digits of the array and store them in an array.
- Pick first 2 digits and form a number and check if it is divisible by 2.
- Pick ith digit and append to the existing number and check if the number is divisible by i.
- If all the above conditions are satisfied until all the digits are exhausted,then the given number is Polydivisible.
Below is the implementation of the above approach.
345654 is Polydivisible number.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check whether all the rotations of a given number is greater than or equal to the given number or not
- Check whether the given number is Euclid Number or not
- Check whether given number N is a Moran Number or not
- Check whether a given number N is a Nude Number or not
- Check whether a given number is an ugly number or not
- Check whether a given Number is Power-Isolated or not
- Check whether the given number is Wagstaff prime or not
- Check whether a number has consecutive 0's in the given base or not
- Check whether the binary equivalent of a number ends with given string or not
- Check Whether a number is Duck Number or not
- Program to check whether a number is Proth number or not
- Check whether a given point lies inside a triangle or not
- Check whether a given matrix is orthogonal or not
- Check whether the given numbers are Cousin prime or not
- Check whether the triangle is valid or not if angles are given
- Check whether Quadrilateral is valid or not if angles are given
- Check whether two points (x1, y1) and (x2, y2) lie on same side of a given line or not
- Check whether triangle is valid or not if three points are given
- Check whether a number is circular prime or not
- Check whether a number has exactly three distinct factors or not
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.