D Numbers | Java implementation for the above approach ; Function to find the N - th icosikaipentagon number ; Number should be greater than 3 ; Check every k in range 2 to n - 1 ; Condition for D - Number ; Driver Code
import java . util . * ; class GFG { static boolean isDNum ( int n ) { if ( n < 4 ) return false ; int numerator = 0 , hcf = 0 ; for ( int k = 2 ; k <= n ; k ++ ) { numerator = ( int ) ( Math . pow ( k , n - 2 ) - k ) ; hcf = __gcd ( n , k ) ; } if ( hcf == 1 && ( numerator % n ) != 0 ) return false ; return true ; } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } public static void main ( String [ ] args ) { int n = 15 ; boolean a = isDNum ( n ) ; if ( a ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }