D Number is a number N > 3 such that N divides k^(n-2)-k for all k with gcd(k, n) = 1, 1<k<n.
9, 15, 21, 33, 39, 51, 57, 63, 69, 87, 93….
Check if a number is a D-Number
Given a number N, the task is to check if N is an D Number or not. If N is an D Number then print “Yes” else print “No”.
Input: N = 9
9 is a D-number since it divides all the numbers
2^7-2, 4^7-4, 5^7-5, 7^7-7 and 8^7-8, and
2, 4, 5, 7, 8 are relatively prime to n.
Input: N = 16
Approach: Since D Number is a number N > 3 such that N divides k^(n-2)-k for all k with gcd(k, n) = 1, 1<k<n. So in a loop of k from 2 to n-1, we will check if gcd of N and k is 1 or not.If it's 1 then we will check if k^(n-2)-k is divisible by N or not.If not divisible we will return false.At last we will return true.
Below is the implementation of the above approach:
Time Complexity: O(1)
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.
- Fill the missing numbers in the array of N natural numbers such that arr[i] not equal to i
- Count of numbers upto M divisible by given Prime Numbers
- Check if a given pair of Numbers are Betrothed numbers or not
- Print N lines of 4 numbers such that every pair among 4 numbers has a GCD K
- Numbers less than N which are product of exactly two distinct prime numbers
- Maximum sum of distinct numbers such that LCM of these numbers is N
- Count numbers which are divisible by all the numbers from 2 to 10
- Count numbers which can be constructed using two numbers
- Number of ways to obtain each numbers in range [1, b+c] by adding any two numbers in range [a, b] and [b, c]
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
- Print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime
- Self Numbers
- Sum of first n even numbers
- Add two numbers using ++ and/or --
- Repunit numbers
- Enlightened Numbers
- Practical Numbers
- Repdigit Numbers
- Superabundant Numbers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.