codeparrot/xlcost-text-to-code huggingface dataset:
Find elements in a given range having at least one odd divisor | Java program to print all numbers with least one odd factor in the given range ; Function to prints all numbers with at least one odd divisor ; Check if the number is not a power of two ; Driver Code
class GFG { static int printOddFactorNumber ( int n , int m ) { for ( int i = n ; i <= m ; i ++ ) { if ( ( i > 0 ) && ( ( i & ( i - 1 ) ) != 0 ) ) System . out . print ( i + " ▁ " ) ; } return 0 ; } public static void main ( String [ ] args ) { int N = 2 , M = 10 ; printOddFactorNumber ( N , M ) ; } }
Print the first N terms of the series 6 , 28 , 66 , 120 , 190 , 276 , ... | Java program for the above approach ; Function to print the series ; Initialise the value of k with 2 ; Iterate from 1 to n ; Print each number ; Increment the value of K by 2 for next number ; Driver code ; Given number N ; Function Call
class GFG { static void printSeries ( int n ) { int k = 2 ; for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( k * ( 2 * k - 1 ) + " ▁ " ) ; k += 2 ; } System . out . println ( ) ; } public static void main ( String args [ ] ) { int N = 12 ; printSeries ( N ) ; } }
Mountain Sequence Pattern | Java program for the above approach ; Function to print pattern recursively ; Base Case ; Condition to check row limit ; Condition for assigning gaps ; Conditions to print * ; Else print ' ▁ ' ; Recursive call for columns ; Recursive call for rows ; Driver code ; Given Number N ; Function Call
class GFG { static int k1 = 2 ; static int k2 = 2 ; static int gap = 5 ; public static int printPattern ( int i , int j , int n ) { if ( j >= n ) { k1 = 2 ; k2 = 2 ; k1 -- ; k2 ++ ; if ( i == 2 ) { k1 = 0 ; k2 = n - 1 ; } return 0 ; } if ( i >= 3 ) { return 1 ; } if ( j > k2 ) { k1 += gap ; k2 += gap ; } if ( j >= k1 && j <= k2 i == 2 ) { System . out . print ( " * " ) ; } else { System . out . print ( " ▁ " ) ; } if ( printPattern ( i , j + 1 , n ) == 1 ) { return 1 ; } System . out . println ( ) ; return printPattern ( i + 1 , 0 , n ) ; } public static void main ( String [ ] args ) { int N = 3 ; printPattern ( 0 , 0 , N * 5 ) ; } }
Build a DFA to accept Binary strings that starts or ends with "01" | Java program to check if a string either starts or ends with 01 ; Function for transition state A ; State transition to B if the character is 0 ; State transition to D if the character is 1 ; Function for transition state B ; Check if the string has ended ; State transition to C if the character is 1 ; State transition to D if the character is 0 ; Function for transition state C ; Function for transition state D ; State transition to D if the character is 1 ; State transition to E if the character is 0 ; Function for transition state E ; State transition to E if the character is 0 ; State transition to F if the character is 1 ; Function for transition state F ; State transition to D if the character is 1 ; State transition to E if the character is 0 ; Driver Code
import java . util . * ; class GFG { static void checkstateA ( String n ) { if ( n . charAt ( 0 ) == '0' ) stateB ( n . substring ( 1 ) ) ; else stateD ( n . substring ( 1 ) ) ; } static void stateB ( String n ) { if ( n . length ( ) == 0 ) System . out . println ( " string ▁ not ▁ accepted " ) ; else { if ( n . charAt ( 0 ) == '1' ) stateC ( n . substring ( 1 ) ) ; else stateD ( n . substring ( 1 ) ) ; } } static void stateC ( String n ) { System . out . println ( " String ▁ accepted " ) ; } static void stateD ( String n ) { if ( n . length ( ) == 0 ) System . out . println ( " string ▁ not ▁ accepted " ) ; else { if ( n . charAt ( 0 ) == '1' ) stateD ( n . substring ( 1 ) ) ; else stateE ( n . substring ( 1 ) ) ; } } static void stateE ( String n ) { if ( n . length ( ) == 0 ) System . out . println ( " string ▁ not ▁ accepted " ) ; else { if ( n . charAt ( 0 ) == '0' ) stateE ( n . substring ( 1 ) ) ; else stateF ( n . substring ( 1 ) ) ; } } static void stateF ( String n ) { if ( n . length ( ) == 0 ) System . out . println ( " string ▁ accepred " ) ; else { if ( n . charAt ( 0 ) == '1' ) stateD ( n . substring ( 1 ) ) ; else stateE ( n . substring ( 1 ) ) ; } } public static void main ( String args [ ] ) { String n = "0100101" ; checkstateA ( n ) ; } }
Find the Nth Hogben Numbers | Java program to print N - th Hogben Number ; Function returns N - th Hogben Number ; Driver code
import java . util . * ; class GFG { public static int HogbenNumber ( int a ) { int p = ( int ) ( Math . pow ( a , 2 ) - a + 1 ) ; return p ; } public static void main ( String args [ ] ) { int N = 10 ; System . out . print ( HogbenNumber ( N ) ) ; } }
Check if left and right shift of any string results into given string | Java program to check if left and right shift of any string results into the given string ; Function to check string exist or not as per above approach ; Check if any character at position i and i + 2 are not equal then string doesnot exist ; Driver Code
class GFG { public static void check_string_exist ( String S ) { int size = S . length ( ) ; boolean check = true ; for ( int i = 0 ; i < size ; i ++ ) { if ( S . charAt ( i ) != S . charAt ( ( i + 2 ) % size ) ) { check = false ; break ; } } if ( check ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void main ( String [ ] args ) { String S = " papa " ; check_string_exist ( S ) ; } }
Cumulative product of digits of all numbers in the given range | Java program to print the product of all numbers in range L and R ; Function to get product of digits ; Function to find the product of digits of all natural numbers in range L to R ; Iterate between L to R ; Driver Code
class GFG { static int getProduct ( int n ) { int product = 1 ; while ( n != 0 ) { product = product * ( n % 10 ) ; n = n / 10 ; } return product ; } static int productinRange ( int l , int r ) { if ( r - l > 9 ) return 0 ; else { int p = 1 ; for ( int i = l ; i <= r ; i ++ ) p *= getProduct ( i ) ; return p ; } } public static void main ( String [ ] args ) { int l = 11 , r = 15 ; System . out . print ( productinRange ( l , r ) + "NEW_LINE"); l = 1 ; r = 15 ; System . out . print ( productinRange ( l , r ) ) ; } }
Check whether the string can be printed using same row of qwerty keypad | Java program to check whether the string can be printed using same row of qwerty keypad ; Function to find the row of the character in the qwerty keypad ; Sets to include the characters from the same row of the qwerty keypad ; Condition to check the row of the current character of the string ; Function to check the characters are from the same row of the qwerty keypad ; Driver code
import java . util . * ; class GFG { static int checkQwertyRow ( char x ) { Character [ ] first_row1 = { '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '0' , ' - ' , ' = ' } ; Set < Character > first_row = new HashSet < > ( Arrays . asList ( first_row1 ) ) ; Character [ ] second_row1 = { ' Q ' , ' W ' , ' E ' , ' R ' , ' T ' , ' Y ' , ' U ' , ' I ' , ' O ' , ' P ' , ' [ ' , ' ] ' , ' q ' , ' w ' , ' e ' , ' r ' , ' t ' , ' y ' , ' u ' , ' i ' , ' o ' , ' p ' } ; Set < Character > second_row = new HashSet < > ( Arrays . asList ( second_row1 ) ) ; Character [ ] third_row1 = { ' A ' , ' S ' , ' D ' , ' F ' , ' G ' , ' H ' , ' J ' , ' K ' , ' L ' , ' ; ' , ' : ' , ' a ' , ' s ' , ' d ' , ' f ' , ' g ' , ' h ' , ' j ' , ' k ' , ' l ' } ; Set < Character > third_row = new HashSet < > ( Arrays . asList ( third_row1 ) ) ; Character [ ] fourth_row1 = { ' Z ' , ' X ' , ' C ' , ' V ' , ' B ' , ' N ' , ' M ' , ' , ' , ' . ' , ' / ' , ' z ' , ' x ' , ' c ' , ' v ' , ' b ' , ' n ' , ' m ' } ; Set < Character > fourth_row = new HashSet < > ( Arrays . asList ( fourth_row1 ) ) ; if ( first_row . contains ( x ) ) { return 1 ; } else if ( second_row . contains ( x ) ) { return 2 ; } else if ( third_row . contains ( x ) ) { return 3 ; } else if ( fourth_row . contains ( x ) ) { return 4 ; } return 0 ; } static boolean checkValidity ( String str ) { char x = str . charAt ( 0 ) ; int row = checkQwertyRow ( x ) ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { x = str . charAt ( i ) ; if ( row != checkQwertyRow ( x ) ) { return false ; } } return true ; } public static void main ( String [ ] args ) { String str = " GeeksforGeeks " ; if ( checkValidity ( str ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }
Last digit of sum of numbers in the given range in the Fibonacci series | Java program to calculate last digit of the sum of the fibonacci numbers from M to N ; Calculate the sum of the first N Fibonacci numbers using Pisano period ; The first two Fibonacci numbers ; Base case ; Pisano period for % 10 is 60 ; Checking the remainder ; The loop will range from 2 to two terms after the remainder ; Driver Code
import java . util . * ; class GFG { static int fib ( long n ) { int f0 = 0 ; int f1 = 1 ; if ( n == 0 ) return 0 ; if ( n == 1 ) return 1 ; else { int rem = ( int ) ( n % 60 ) ; if ( rem == 0 ) return 0 ; for ( int i = 2 ; i < rem + 3 ; i ++ ) { int f = ( f0 + f1 ) % 60 ; f0 = f1 ; f1 = f ; } int s = f1 - 1 ; return s ; } } public static void main ( String args [ ] ) { int m = 10087887 ; long n = 2983097899L ; int Final = ( int ) Math . abs ( fib ( n ) - fib ( m - 1 ) ) ; System . out . println ( Final % 10 ) ; } }
Find N values of X1 , X2 , ... Xn such that X1 < X2 < ... < XN and sin ( X1 ) < sin ( X2 ) < ... < sin ( XN ) | Java program for the above approach ; Function to print all such Xi s . t . all Xi and sin ( Xi ) are strictly increasing ; Till N becomes zero ; Find the value of sin ( ) using inbuilt function ; Increment by 710 ; Driver Code ; Function Call
import java . util . * ; class GFG { static void printSinX ( int N ) { int Xi = 0 ; int num = 1 ; while ( N -- > 0 ) { System . out . print ( " X " + num + " ▁ = ▁ " + Xi ) ; System . out . print ( " ▁ sin ( X " + num + " ) ▁ = ▁ " ) ; System . out . printf ( " % .6f " , Math . sin ( Xi ) ) ; System . out . println ( ) ; num += 1 ; Xi += 710 ; } } public static void main ( String [ ] args ) { int N = 5 ; printSinX ( N ) ; } }
Sum of all elements in an array between zeros | Java program for the above approach ; Function to find the sum between two zeros in the given array arr [ ] ; To store the sum of element between two zeros ; To store the sum ; Find first index of 0 ; Traverse the given array arr [ ] ; If 0 occurs then add it to A [ ] ; Else add element to the sum ; Print all the sum stored in A ; If there is no such element print - 1 ; Driver Code ; Function call
import java . util . * ; class GFG { static void sumBetweenZero ( int arr [ ] , int N ) { int i = 0 ; Vector < Integer > A = new Vector < Integer > ( ) ; int sum = 0 ; for ( i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 0 ) { i ++ ; break ; } } for ( ; i < N ; i ++ ) { if ( arr [ i ] == 0 ) { A . add ( sum ) ; sum = 0 ; } else { sum += arr [ i ] ; } } for ( int j = 0 ; j < A . size ( ) ; j ++ ) { System . out . print ( A . get ( j ) + " ▁ " ) ; } if ( A . size ( ) == 0 ) System . out . print ( " - 1" ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 0 , 3 , 4 , 0 , 4 , 4 , 0 , 2 , 1 , 4 , 0 , 3 } ; int N = arr . length ; sumBetweenZero ( arr , N ) ; } }
Find the Nth term of the series 2 , 15 , 41 , 80 , 132. . . | Java program for the above approach ; Recursive function to find Nth term ; Base Case ; Recursive Call according to Nth term of the series ; Driver Code ; Input Nth term ; Function call
class GFG { static int nthTerm ( int N ) { if ( N == 1 ) { return 2 ; } return ( ( N - 1 ) * 13 ) + nthTerm ( N - 1 ) ; } public static void main ( String [ ] args ) { int N = 17 ; System . out . print ( nthTerm ( N ) + "NEW_LINE"); } }
Subsequence pair from given Array having all unique and all same elements respectively | Java program for the above approach ; Function to find the maximum length of subsequences with given property ; To store the frequency ; Traverse the array to store the frequency ; M . size ( ) given count of distinct element in arr [ ] ; Traverse map to find max frequency ; Find the maximum length on the basis of two cases in the approach ; Driver Code ; Function call
import java . util . * ; class GFG { static void maximumSubsequence ( int arr [ ] , int N ) { HashMap < Integer , Integer > M = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( M . containsKey ( arr [ i ] ) ) { M . put ( arr [ i ] , M . get ( arr [ i ] ) + 1 ) ; } else { M . put ( arr [ i ] , 1 ) ; } } int distinct_size = M . size ( ) ; int maxFreq = 1 ; for ( Map . Entry < Integer , Integer > it : M . entrySet ( ) ) { maxFreq = Math . max ( maxFreq , it . getValue ( ) ) ; } System . out . print ( Math . max ( Math . min ( distinct_size , maxFreq - 1 ) , Math . min ( distinct_size - 1 , maxFreq ) ) ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 4 , 4 , 4 , 4 , 5 } ; int N = arr . length ; maximumSubsequence ( arr , N ) ; } }
Total length of string from given Array of strings composed using given characters | Java implementation to find total length of string composed of given characters formed from given Array of strings ; Function to count the total length ; Map for keeping frequency of characters ; Calculate the frequency ; Iterate in the N strings ; Iterates in the string ; Checks if given character of string string appears in it or not ; Adds the length of string if all characters are present ; Return the final result ; Driver code
import java . util . * ; class GFG { static int countCharacters ( List < String > strings , String chars ) { int res = 0 ; Map < Character , Integer > freq = new HashMap < > ( ) ; for ( int i = 0 ; i < chars . length ( ) ; i ++ ) { freq . put ( chars . charAt ( i ) , freq . getOrDefault ( chars . charAt ( i ) , 0 ) + 1 ) ; } for ( String st : strings ) { boolean flag = true ; for ( char c : st . toCharArray ( ) ) { if ( ! freq . containsKey ( c ) ) { flag = false ; break ; } } if ( flag ) res += st . length ( ) ; } return res ; } public static void main ( String [ ] args ) { List < String > strings = Arrays . asList ( " hi " , " data " , " geeksforgeeks " ) ; String chars = " tiadhae " ; System . out . println ( countCharacters ( strings , chars ) ) ; } }
Construct an Array of size N in which sum of odd elements is equal to sum of even elements | Java program to Create an array of size N consisting of distinct elements where sum of odd elements is equal to sum of even elements ; Function to construct the required array ; To confirst half , distinct even numbers ; To consecond half , distinct odd numbers ; Calculate the last number of second half so as to make both the halves equal ; Function to construct the required array ; check if size is multiple of 4 then array exist ; function call to conarray ; Driver code
class GFG { static void arrayConstruct ( int N ) { for ( int i = 2 ; i <= N ; i = i + 2 ) System . out . print ( i + " ▁ " ) ; for ( int i = 1 ; i < N - 1 ; i = i + 2 ) System . out . print ( i + " ▁ " ) ; System . out . print ( N - 1 + ( N / 2 ) + "NEW_LINE"); } static void createArray ( int N ) { if ( N % 4 == 0 ) arrayConstruct ( N ) ; else System . out . print ( - 1 + "NEW_LINE"); } public static void main ( String [ ] args ) { int N = 8 ; createArray ( N ) ; } }
Count of all sub | Java implementation to count all sub - strings with sum of weights at most K ; Function to count all substrings ; Hashmap to store substrings ; Iterate over all substrings ; Variable to maintain sum of all characters encountered ; Variable to maintain substring till current position ; Get position of character in string W ; Add weight to current sum ; Add current character to substring ; Check if sum of characters is <= K insert in Hashmap ; Driver Code ; Initialise string ; Initialise weight
import java . io . * ; import java . util . * ; class GFG { static int distinctSubstring ( String P , String Q , int K , int N ) { Set < String > S = new HashSet < > ( ) ; for ( int i = 0 ; i < N ; ++ i ) { int sum = 0 ; String s = " " ; for ( int j = i ; j < N ; ++ j ) { int pos = P . charAt ( j ) - ' a ' ; sum += Q . charAt ( pos ) - '0' ; s += P . charAt ( j ) ; if ( sum <= K ) { S . add ( s ) ; } else { break ; } } } return S . size ( ) ; } public static void main ( String args [ ] ) { String S = " abcde " ; String W = "12345678912345678912345678" ; int K = 5 ; int N = S . length ( ) ; System . out . println ( distinctSubstring ( S , W , K , N ) ) ; } }
Minimum characters required to make a password strong | Java program to find minimum number of characters required to be added to make a password strong ; Function to count minimum number of characters ; Create the patterns to search digit , upper case alphabet , lower case alphabet and special character ; Search the above patterns in password . ; If no digits are present ; If no upper case alphabet is present ; If no lower case alphabet is present ; If no special character is is present ; Check if the string length after adding the required characters is less than 8 ; Add the number of characters to be added ; Driver Code
import java . util . regex . Pattern ; import java . util . regex . Matcher ; class GFG { static int countCharacters ( String password ) { int count = 0 ; Pattern digit = Pattern . compile ( " ( \\ d ) " ) ; Pattern upper = Pattern . compile ( " ( [ A - Z ] ) " ) ; Pattern lower = Pattern . compile ( " ( [ a - z ] ) " ) ; Pattern spChar = Pattern . compile ( " ( \\ W ) " ) ; Matcher Digit = digit . matcher ( password ) ; Matcher Upper = upper . matcher ( password ) ; Matcher Lower = lower . matcher ( password ) ; Matcher Special = spChar . matcher ( password ) ; if ( ! Digit . find ( ) ) { count ++ ; } if ( ! Upper . find ( ) ) { count ++ ; } if ( ! Lower . find ( ) ) { count ++ ; } if ( ! Special . find ( ) ) { count ++ ; } if ( ( count + password . length ( ) ) < 8 ) { count = count + 8 - ( count + password . length ( ) ) ; } return count ; } public static void main ( String args [ ] ) { String password1 = " Geeksforgeeks " ; System . out . println ( countCharacters ( password1 ) ) ; String password2 = " Geeks1" ; System . out . println ( countCharacters ( password2 ) ) ; } }
Count all sub | Java program to find the count of all the sub - Strings with weight of characters atmost K ; Function to find the count of all the subStrings with weight of characters atmost K ; Hashmap to store all subStrings ; Iterate over all subStrings ; Maintain the sum of all characters encountered so far ; Maintain the subString till the current position ; Get the position of the character in String Q ; Add weight to current sum ; Add current character to subString ; If sum of characters is <= K then insert in into the set ; Finding the size of the set ; Driver code
import java . util . * ; class GFG { static int distinctSubString ( String P , String Q , int K , int N ) { HashSet < String > S = new HashSet < String > ( ) ; for ( int i = 0 ; i < N ; ++ i ) { int sum = 0 ; String s = " " ; for ( int j = i ; j < N ; ++ j ) { int pos = P . charAt ( j ) - ' a ' ; sum += Q . charAt ( pos ) - '0' ; s += P . charAt ( j ) ; if ( sum <= K ) { S . add ( s ) ; } else { break ; } } } return S . size ( ) ; } public static void main ( String [ ] args ) { String P = " abcde " ; String Q = "12345678912345678912345678" ; int K = 5 ; int N = P . length ( ) ; System . out . print ( distinctSubString ( P , Q , K , N ) ) ; } }
Program to print a Hollow Triangle inside a Triangle | Java implementation of the above approach ; Function to print the pattern ; Loop for rows ; Loop for column ; For printing equal sides of outer triangle ; For printing equal sides of inner triangle ; For printing base of both triangle ; For spacing between the triangle ; Driver Code
import java . util . * ; class GFG { static void printPattern ( int n ) { int i , j ; for ( i = 1 ; i <= n ; i ++ ) { for ( j = 1 ; j < 2 * n ; j ++ ) { if ( j == ( n - i + 1 ) || j == ( n + i - 1 ) ) { System . out . print ( " * ▁ " ) ; } else if ( ( i >= 4 && i <= n - 4 ) && ( j == n - i + 4 j == n + i - 4 ) ) { System . out . print ( " * ▁ " ) ; } else if ( i == n || ( i == n - 4 && j >= n - ( n - 2 * 4 ) && j <= n + n - 2 * 4 ) ) { System . out . print ( " * ▁ " ) ; } else { System . out . print ( " ▁ " + " ▁ " ) ; } } System . out . print ( "NEW_LINE"); } } public static void main ( String [ ] args ) { int N = 9 ; printPattern ( N ) ; } }
Check if a string is made up of K alternating characters | Java implementation of the approach ; Function to check if a String is made up of k alternating characters ; Check if all the characters at indices 0 to K - 1 are different ; If that bit is already set in checker , return false ; Otherwise update and continue by setting that bit in the checker ; Driver code
class GFG { static boolean isKAlternating ( String s , int k ) { if ( s . length ( ) < k ) return false ; int checker = 0 ; for ( int i = 0 ; i < k ; i ++ ) { int bitAtIndex = s . charAt ( i ) - ' a ' ; if ( ( checker & ( 1 << bitAtIndex ) ) > 0 ) { return false ; } checker = checker | ( 1 << bitAtIndex ) ; } for ( int i = k ; i < s . length ( ) ; i ++ ) if ( s . charAt ( i - k ) != s . charAt ( i ) ) return false ; return true ; } public static void main ( String [ ] args ) { String str = " acdeac " ; int K = 4 ; if ( isKAlternating ( str , K ) ) System . out . print ( " Yes " + "NEW_LINE"); else System . out . print ( " No " + "NEW_LINE"); } }
Find all Factors of Large Perfect Square Natural Number in O ( sqrt ( sqrt ( N ) ) | Java program to find the factors of large perfect square number in O ( Math . sqrt ( Math . sqrt ( N ) ) ) time ; Function that find all the prime factors of N ; Store the Math . sqrt ( N ) in temp ; Initialise factor array with 1 as a factor in it ; Check divisibility by 2 ; Store the factors twice ; Check for other prime factors other than 2 ; If j is a prime factor ; Store the prime factor twice ; If j is prime number left other than 2 ; Store j twice ; Initialise Matrix M to to store all the factors ; tpc for rows tpr for column ; Initialise M [ 0 ] [ 0 ] = 1 as it also factor of N ; Traversing factor array ; If current and previous factors are not same then move to next row and insert the current factor ; If current and previous factors are same then , Insert the factor with previous factor inserted in matrix M ; The arr1 [ ] and arr2 [ ] used to store all the factors of N ; Initialise arrays as 1 ; Traversing the matrix M ; Traversing till column element doesn 't become 0 ; Store the product of every element of current row with every element in arr1 [ ] ; Copying every element of arr2 [ ] in arr1 [ ] ; length of arr2 [ ] and arr1 [ ] are equal after copying ; Print all the factors ; Drivers Code
import java . util . * ; class GFG { static int MAX = 100000 ; static void findFactors ( int N ) { int temp = ( int ) Math . sqrt ( N ) ; int [ ] factor = new int [ MAX ] ; Arrays . fill ( factor , 1 ) ; int i , j , k ; int len1 = 1 ; while ( temp % 2 == 0 ) { factor [ len1 ++ ] = 2 ; factor [ len1 ++ ] = 2 ; temp /= 2 ; } for ( j = 3 ; j < Math . sqrt ( temp ) ; j += 2 ) { while ( temp % j == 0 ) { factor [ len1 ++ ] = j ; factor [ len1 ++ ] = j ; temp /= j ; } } if ( temp > 2 ) { factor [ len1 ++ ] = temp ; factor [ len1 ++ ] = temp ; } int [ ] [ ] M = new int [ len1 ] [ MAX ] ; int tpc = 0 , tpr = 0 ; M [ 0 ] [ 0 ] = 1 ; j = 1 ; while ( j < len1 ) { if ( factor [ j ] != factor [ j - 1 ] ) { tpr ++ ; M [ tpr ] [ 0 ] = factor [ j ] ; j ++ ; tpc = 1 ; } else { M [ tpr ] [ tpc ] = M [ tpr ] [ tpc - 1 ] * factor [ j ] ; j ++ ; tpc ++ ; } } int [ ] arr1 = new int [ MAX ] ; int [ ] arr2 = new int [ MAX ] ; int l1 , l2 ; l1 = l2 = 1 ; arr1 [ 0 ] = arr2 [ 0 ] = 1 ; for ( i = 1 ; i < tpr + 1 ; i ++ ) { for ( j = 0 ; M [ i ] [ j ] != 0 ; j ++ ) { for ( k = 0 ; k < l1 ; k ++ ) { arr2 [ l2 ++ ] = arr1 [ k ] * M [ i ] [ j ] ; } } for ( j = l1 ; j < l2 ; j ++ ) { arr1 [ j ] = arr2 [ j ] ; } l1 = l2 ; } for ( i = 0 ; i < l2 ; i ++ ) { System . out . print ( arr2 [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int N = 900 ; findFactors ( N ) ; } }