codeparrot/xlcost-text-to-code huggingface dataset:
Find prime factors of Array elements whose sum of exponents is divisible by K | Java program for the above approach ; To store the smallest prime factor till 10 ^ 5 ; Function to compute smallest prime factor array ; Initialize the spf array first element ; Marking smallest prime factor for every number to be itself ; Separately marking smallest prime factor for every even number as 2 ; Checking if i is prime ; Marking SPF for all numbers divisible by i ; Marking spf [ j ] if it is not previously marked ; Function that finds minimum operation ; Create a spf [ ] array ; Map created to store the unique prime numbers ; To store the result ; To store minimum operations ; To store every unique prime number ; Erase 1 as a key because it is not a prime number ; First prime number ; Frequency is divisible by K then insert primeNum in the result [ ] ; Print the elements if it exists ; Driver code ; Given array arr [ ] ; Given K ; Function call
import java . util . * ; class GFG { static int [ ] spf = new int [ 10001 ] ; static void spf_array ( int spf [ ] ) { spf [ 1 ] = 1 ; for ( int i = 2 ; i < 1000 ; i ++ ) spf [ i ] = i ; for ( int i = 4 ; i < 1000 ; i += 2 ) spf [ i ] = 2 ; for ( int i = 3 ; i * i < 1000 ; i ++ ) { if ( spf [ i ] == i ) { for ( int j = i * i ; j < 1000 ; j += i ) if ( spf [ j ] == j ) spf [ j ] = i ; } } } static void frequent_prime ( int arr [ ] , int N , int K ) { spf_array ( spf ) ; Map < Integer , Integer > Hmap = new TreeMap < > ( ) ; ArrayList < Integer > result = new ArrayList < > ( ) ; int i = 0 ; int c = 0 ; for ( i = 0 ; i < N ; i ++ ) { int x = arr [ i ] ; while ( x != 1 ) { Hmap . put ( spf [ x ] , Hmap . getOrDefault ( spf [ x ] , 0 ) + 1 ) ; x = x / spf [ x ] ; } } Hmap . remove ( 1 ) ; for ( Map . Entry < Integer , Integer > x : Hmap . entrySet ( ) ) { int primeNum = x . getKey ( ) ; int frequency = x . getValue ( ) ; if ( frequency % K == 0 ) { result . add ( primeNum ) ; } } if ( result . size ( ) > 0 ) { for ( Integer it : result ) { System . out . print ( it + " ▁ " ) ; } } else { System . out . print ( " { } " ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 4 , 6 } ; int K = 1 ; int N = arr . length ; frequent_prime ( arr , N , K ) ; } }
Generate first K multiples of N using Bitwise operators | Java program to implement the above approach ; Function to print the first K multiples of N ; Print the value of N * i ; Iterate each bit of N and add Math . pow ( 2 , pos ) , where pos is the index of each set bit ; Check if current bit at pos j is fixed or not ; For next set bit ; Driver Code
import java . util . * ; class GFG { static void Kmultiples ( int n , int k ) { int a = n ; for ( int i = 1 ; i <= k ; i ++ ) { System . out . print ( n + " ▁ * ▁ " + i + " ▁ = ▁ " + a + "NEW_LINE"); int j = 0 ; while ( n >= ( 1 << j ) ) { a += n & ( 1 << j ) ; j ++ ; } } } public static void main ( String [ ] args ) { int N = 16 , K = 7 ; Kmultiples ( N , K ) ; } }
Least Square Regression Line | Java program to find the regression line ; Function to calculate b ; sum of array x ; sum of array y ; for sum of product of x and y ; sum of square of x ; Function to find the least regression line ; Finding b ; calculating a ; Printing regression line ; Driver code ; statistical data
import java . util . Arrays ; public class GFG { private static double calculateB ( int [ ] x , int [ ] y ) { int n = x . length ; int sx = Arrays . stream ( x ) . sum ( ) ; int sy = Arrays . stream ( y ) . sum ( ) ; int sxsy = 0 ; int sx2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sxsy += x [ i ] * y [ i ] ; sx2 += x [ i ] * x [ i ] ; } double b = ( double ) ( n * sxsy - sx * sy ) / ( n * sx2 - sx * sx ) ; return b ; } public static void leastRegLine ( int X [ ] , int Y [ ] ) { double b = calculateB ( X , Y ) ; int n = X . length ; int meanX = Arrays . stream ( X ) . sum ( ) / n ; int meanY = Arrays . stream ( Y ) . sum ( ) / n ; double a = meanY - b * meanX ; System . out . println ( " Regression ▁ line : " ) ; System . out . print ( " Y ▁ = ▁ " ) ; System . out . printf ( " % .3f " , a ) ; System . out . print ( " ▁ + ▁ " ) ; System . out . printf ( " % .3f " , b ) ; System . out . print ( " * X " ) ; } public static void main ( String [ ] args ) { int X [ ] = { 95 , 85 , 80 , 70 , 60 } ; int Y [ ] = { 90 , 80 , 70 , 65 , 60 } ; leastRegLine ( X , Y ) ; } }
Count of repeating digits in a given Number | Java program for the above approach ; Function that returns the count of repeating digits of the given number ; Initialize a variable to store count of Repeating digits ; Initialize cnt array to store digit count ; Iterate through the digits of N ; Retrieve the last digit of N ; Increase the count of digit ; Remove the last digit of N ; Iterate through the cnt array ; If frequency of digit is greater than 1 ; Increment the count of Repeating digits ; Return count of repeating digit ; Driver Code ; Given array arr [ ] ; Function Call
class GFG { static int countRepeatingDigits ( int N ) { int res = 0 ; int cnt [ ] = new int [ 10 ] ; while ( N > 0 ) { int rem = N % 10 ; cnt [ rem ] ++ ; N = N / 10 ; } for ( int i = 0 ; i < 10 ; i ++ ) { if ( cnt [ i ] > 1 ) { res ++ ; } } return res ; } public static void main ( String [ ] args ) { int N = 12 ; System . out . println ( countRepeatingDigits ( N ) ) ; } }
Find temperature of missing days using given sum and average | Java program for the above approach ; Function for finding the temperature ; Store Day1 - Day2 in diff ; Remaining from s will be Day1 ; Print Day1 and Day2 ; Driver Code ; Functions
class GFG { static void findTemperature ( int x , int y , int s ) { double Day1 , Day2 ; double diff = ( x - y ) * 6 ; Day2 = ( diff + s ) / 2 ; Day1 = s - Day2 ; System . out . println ( " Day1 ▁ : ▁ " + Day1 ) ; System . out . println ( " Day2 ▁ : ▁ " + Day2 ) ; } public static void main ( String [ ] args ) { int x = 5 , y = 10 , s = 40 ; findTemperature ( x , y , s ) ; } }
Find two numbers whose sum is N and does not contain any digit as K | Java program for the above approach ; Function to find two numbers whose sum is N and do not contain any digit as k ; Check every number i and ( n - i ) ; Check if i and n - i doesn 't  contain k in them print i and n-i ; Check if flag is 0 then print - 1 ; Driver code ; Given N and K ; Function call
import java . util . * ; class GFG { static int freqCount ( String str , char k ) { int count = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str . charAt ( i ) == k ) count ++ ; } return count ; } static void findAandB ( int n , int k ) { int flag = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( freqCount ( Integer . toString ( i ) , ( char ) ( k + 48 ) ) == 0 && freqCount ( Integer . toString ( n - i ) , ( char ) ( k + 48 ) ) == 0 ) { System . out . print ( " ( " + i + " , ▁ " + ( n - i ) + " ) " ) ; flag = 1 ; break ; } } if ( flag == 0 ) System . out . print ( - 1 ) ; } public static void main ( String [ ] args ) { int N = 100 ; int K = 0 ; findAandB ( N , K ) ; } }
Find the value of P and modular inverse of Q modulo 998244353 | Java implementation to find the value of P . Q - 1 mod 998244353 ; Function to find the value of P * Q ^ - 1 mod 998244353 ; Loop to find the value until the expo is not zero ; Multiply p with q if expo is odd ; Reduce the value of expo by 2 ; Driver code ; Function call
import java . util . * ; class GFG { static long calculate ( long p , long q ) { long mod = 998244353 , expo ; expo = mod - 2 ; while ( expo != 0 ) { if ( ( expo & 1 ) == 1 ) { p = ( p * q ) % mod ; } q = ( q * q ) % mod ; expo >>= 1 ; } return p ; } public static void main ( String [ ] args ) { long p = 1 , q = 4 ; System . out . println ( calculate ( p , q ) ) ; } }
Find two numbers with given sum and maximum possible LCM | Java program of the above approach ; Function that print two numbers with the sum X and maximum possible LCM ; Variables to store the result ; If X is odd ; If X is even ; If floor ( X / 2 ) is even ; If floor ( X / 2 ) is odd ; Print the result ; Driver code ; Given number ; Function call
import java . util . * ; class GFG { static void maxLCMWithGivenSum ( int X ) { int A , B ; if ( ( X & 1 ) == 1 ) { A = X / 2 ; B = X / 2 + 1 ; } else { if ( ( X / 2 ) % 2 == 0 ) { A = X / 2 - 1 ; B = X / 2 + 1 ; } else { A = X / 2 - 2 ; B = X / 2 + 2 ; } } System . out . println ( A + " ▁ " + B ) ; } public static void main ( String [ ] args ) { int X = 30 ; maxLCMWithGivenSum ( X ) ; } }
Length of longest subarray whose sum is not divisible by integer K | Java program to find the length of the longest subarray whose sum is not divisible by integer K ; Function to find the longest subarray with sum is not divisible by k ; left is the index of the leftmost element that is not divisible by k ; right is the index of the rightmost element that is not divisible by k ; sum of the array ; Find the element that is not multiple of k ; left = - 1 means we are finding the leftmost element that is not divisible by k ; Updating the rightmost element ; Update the sum of the array up to the index i ; Check if the sum of the array is not divisible by k , then return the size of array ; All elements of array are divisible by k , then no such subarray possible so return - 1 ; Length of prefix elements that can be removed ; Length of suffix elements that can be removed ; Return the length of subarray after removing the elements which have lesser number of elements ; Driver code
import java . util . * ; class GFG { static int MaxSubarrayLength ( int arr [ ] , int n , int k ) { int left = - 1 ; int right = 0 ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( arr [ i ] % k ) != 0 ) { if ( left == - 1 ) { left = i ; } right = i ; } sum += arr [ i ] ; } if ( ( sum % k ) != 0 ) { return n ; } else if ( left == - 1 ) { return - 1 ; } else { int prefix_length = left + 1 ; int suffix_length = n - right ; return n - Math . min ( prefix_length , suffix_length ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 6 , 3 , 12 , 15 } ; int n = arr . length ; int K = 3 ; System . out . println ( MaxSubarrayLength ( arr , n , K ) ) ; } }
Minimum steps to convert X to Y by repeated division and multiplication | Java implementation to find minimum steps to convert X to Y by repeated division and multiplication ; Check if X is greater than Y then swap the elements ; Check if X equals Y ; Driver code
class GFG { static int solve ( int X , int Y ) { if ( X > Y ) { int temp = X ; X = Y ; Y = temp ; } if ( X == Y ) System . out . println ( 0 ) ; else if ( Y % X == 0 ) System . out . println ( 1 ) ; else System . out . println ( 2 ) ; return 0 ; } public static void main ( String args [ ] ) { int X = 8 , Y = 13 ; solve ( X , Y ) ; } }
Count quadruplets ( A , B , C , D ) till N such that sum of square of A and B is equal to that of C and D | Java program for the above approach ; Function to count the quadruples ; Counter variable ; Map to store the sum of pair ( a ^ 2 + b ^ 2 ) ; Iterate till N ; Calculate a ^ 2 + b ^ 2 ; Increment the value in map ; Check if this sum was also in a ^ 2 + b ^ 2 ; Return the count ; Driver code ; Given N ; Function call
import java . util . * ; class GFG { static long countQuadraples ( long N ) { long cnt = 0 ; Map < Long , Long > m = new HashMap < > ( ) ; for ( long a = 1 ; a <= N ; a ++ ) { for ( long b = 1 ; b <= N ; b ++ ) { long x = a * a + b * b ; m . put ( x , m . getOrDefault ( x , 0l ) + 1 ) ; } } for ( long c = 1 ; c <= N ; c ++ ) { for ( long d = 1 ; d <= N ; d ++ ) { long x = c * c + d * d ; if ( m . containsKey ( x ) ) cnt += m . get ( x ) ; } } return cnt ; } public static void main ( String [ ] args ) { long N = 2 ; System . out . println ( countQuadraples ( N ) ) ; } }
Count of distinct index pair ( i , j ) such that element sum of First Array is greater | Java program for the above problem ; function to find the number of pairs satisfying the given cond . ; variables used for traversal ; count variable to store the count of possible pairs ; Nested loop to find out the possible pairs ; Check if the given condition is satisfied or not . If yes then increment the count . ; Return the count value ; Driver Code ; Size of the arrays ; Initialise the arrays ; function call that returns the count of possible pairs
class GFG { static int count_pairs ( int [ ] a , int b [ ] , int N ) { int i , j ; int count = 0 ; for ( i = 0 ; i < ( N - 1 ) ; i ++ ) { for ( j = ( i + 1 ) ; j < N ; j ++ ) { if ( ( a [ i ] + a [ j ] ) > ( b [ i ] + b [ j ] ) ) { count ++ ; } } } return count ; } public static void main ( String [ ] args ) { int N = 5 ; int a [ ] = new int [ ] { 1 , 2 , 3 , 4 , 5 } ; int b [ ] = new int [ ] { 2 , 5 , 6 , 1 , 9 } ; System . out . println ( count_pairs ( a , b , N ) ) ; } }
Count of distinct index pair ( i , j ) such that element sum of First Array is greater | Java program of the above approach ; Function to find the number of pairs . ; Array c [ ] where c [ i ] = a [ i ] - b [ i ] ; Sort the array c ; Initialise answer as 0 ; Iterate from index 0 to n - 1 ; If c [ i ] <= 0 then in the sorted array c [ i ] + c [ pos ] can never greater than 0 where pos < i ; Which is equivalent to c [ j ] >= - c [ i ] + 1 ; Add ( i - pos ) to answer ; Return the answer ; Driver code ; Number of elements in a and b ; array a ; array b
import java . util . * ; class GFG { static int numberOfPairs ( int [ ] a , int [ ] b , int n ) { int c [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { c [ i ] = a [ i ] - b [ i ] ; } Arrays . sort ( c ) ; int answer = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( c [ i ] <= 0 ) continue ; int pos = - 1 ; for ( int j = 0 ; j < n ; j ++ ) { if ( c [ i ] + c [ j ] > 0 ) { pos = j ; break ; } } answer += ( i - pos ) ; } return answer ; } public static void main ( String [ ] args ) { int n = 5 ; int a [ ] = { 1 , 2 , 3 , 4 , 5 } ; int b [ ] = { 2 , 5 , 6 , 1 , 9 } ; System . out . println ( numberOfPairs ( a , b , n ) ) ; } }
Find K for every Array element such that at least K prefixes are â ‰¥ K | Java program for the above approach ; Function to find the K - value for every index in the array ; Multiset to store the array in the form of red - black tree ; Iterating over the array ; Inserting the current value in the multiset ; Condition to check if the smallest value in the set is less than it 's size ; Erase the smallest value ; h - index value will be the size of the multiset ; Driver code ; Array ; Size of the array ; Function call
import java . util . * ; class GFG { static void print_h_index ( int arr [ ] , int N ) { List < Integer > ms = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { ms . add ( arr [ i ] ) ; int t = Collections . min ( ms ) ; if ( t < ms . size ( ) ) { ms . remove ( ms . indexOf ( t ) ) ; } System . out . print ( ms . size ( ) + " ▁ " ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 9 , 10 , 7 , 5 , 0 , 10 , 2 , 0 } ; int N = arr . length ; print_h_index ( arr , N ) ; } }
Non | Java program to find Non - repeating Primes ; Function to find count of prime ; Find maximum value in the array ; Create a boolean array " prime [ 0 . . n ] " . A value in prime [ i ] will finally be false if i is Not a prime , else true . ; Remaining part of SIEVE ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p ; Function to print Non - repeating primes ; Precompute primes using Sieve ; Create HashMap to store frequency of prime numbers ; Traverse through array elements and Count frequencies of all primes ; Traverse through map and print non repeating primes ; Driver code
import java . util . * ; class GFG { static Vector < Boolean > findPrimes ( int arr [ ] , int n ) { int max_val = Arrays . stream ( arr ) . max ( ) . getAsInt ( ) ; Vector < Boolean > prime = new Vector < > ( max_val + 1 ) ; for ( int i = 0 ; i < max_val + 1 ; i ++ ) prime . add ( i , Boolean . TRUE ) ; prime . add ( 0 , Boolean . FALSE ) ; prime . add ( 1 , Boolean . FALSE ) ; for ( int p = 2 ; p * p <= max_val ; p ++ ) { if ( prime . get ( p ) == true ) { for ( int i = p * 2 ; i <= max_val ; i += p ) prime . add ( i , Boolean . FALSE ) ; } } return prime ; } static void nonRepeatingPrimes ( int arr [ ] , int n ) { Vector < Boolean > prime = findPrimes ( arr , n ) ; HashMap < Integer , Integer > mp = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( prime . get ( arr [ i ] ) ) if ( mp . containsKey ( arr [ i ] ) ) mp . put ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ; else mp . put ( arr [ i ] , 1 ) ; } for ( Map . Entry < Integer , Integer > entry : mp . entrySet ( ) ) { if ( entry . getValue ( ) == 1 ) System . out . println ( entry . getKey ( ) ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 4 , 6 , 7 , 9 , 7 , 23 , 21 , 3 } ; int n = arr . length ; nonRepeatingPrimes ( arr , n ) ; } }
Prefix Product Array | Java program to generate Prefix Product Array ; Function to generate prefix product array ; Update the array with the product of prefixes ; Print the array ; Driver Code
class GFG { static int prefixProduct ( int [ ] a , int n ) { for ( int i = 1 ; i < n ; i ++ ) { a [ i ] = a [ i ] * a [ i - 1 ] ; } for ( int j = 0 ; j < n ; j ++ ) { System . out . print ( a [ j ] + " , ▁ " ) ; } return 0 ; } public static void main ( String [ ] args ) { int arr [ ] = new int [ ] { 2 , 4 , 6 , 5 , 10 } ; int N = 5 ; prefixProduct ( arr , N ) ; } }
Count of ways to distribute N items among 3 people with one person receiving maximum | Java program to find the number of ways to distribute N item among three people such that one person always gets the maximum value ; Function to find the number of ways to distribute N items among 3 people ; No distribution possible ; Total number of ways to distribute N items among 3 people ; Store the number of distributions which are not possible ; Count possibilities of two persons receiving the maximum ; If N is divisible by 3 ; Return the final count of ways to distribute ; Driver Code
class GFG { static int countWays ( int N ) { if ( N < 4 ) return 0 ; int ans = ( ( N - 1 ) * ( N - 2 ) ) / 2 ; int s = 0 ; for ( int i = 2 ; i <= N - 3 ; i ++ ) { for ( int j = 1 ; j < i ; j ++ ) { if ( N == 2 * i + j ) s ++ ; } } if ( N % 3 == 0 ) s = 3 * s + 1 ; else s = 3 * s ; return ans - s ; } public static void main ( String [ ] args ) { int N = 10 ; System . out . println ( countWays ( N ) ) ; } }
Magnanimous Numbers | Java implementation to check if a number is Magnanimous ; Function to check if n is prime ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Function to check if the number is Magnanimous or not ; Converting the number to string ; Finding length of string ; Number should not be of single digit ; Loop to find all left and right part of the string ; Driver code
class GFG { static boolean isPrime ( int n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } static boolean isMagnanimous ( int N ) { String s = Integer . toString ( N ) ; int l = s . length ( ) ; if ( l < 2 ) return false ; for ( int i = 0 ; i < l - 1 ; i ++ ) { String left = s . substring ( 0 , i + 1 ) ; String right = s . substring ( i + 1 ) ; int x = Integer . valueOf ( left ) ; int y = Integer . valueOf ( right ) ; if ( ! isPrime ( x + y ) ) return false ; } return true ; } public static void main ( String [ ] args ) { int N = 12 ; if ( isMagnanimous ( N ) ) System . out . print ( "YesNEW_LINE"); else System . out . print ( "NoNEW_LINE"); } }
Honaker Prime Number | Java program for above approach ; Function to precompute the position of every prime number using Sieve ; 0 and 1 are not prime numbers ; Variable to store the position ; Incrementing the position for every prime number ; Function to get sum of digits ; Function to check whether the given number is Honaker Prime number or not ; Driver code ; Precompute the prime numbers till 10 ^ 6 ; Given Number ; Function Call
class GFG { static final int limit = 10000000 ; static int [ ] position = new int [ limit + 1 ] ; static void sieve ( ) { position [ 0 ] = - 1 ; position [ 1 ] = - 1 ; int pos = 0 ; for ( int i = 2 ; i <= limit ; i ++ ) { if ( position [ i ] == 0 ) { position [ i ] = ++ pos ; for ( int j = i * 2 ; j <= limit ; j += i ) position [ j ] = - 1 ; } } } static int getSum ( int n ) { int sum = 0 ; while ( n != 0 ) { sum = sum + n % 10 ; n = n / 10 ; } return sum ; } static boolean isHonakerPrime ( int n ) { int pos = position [ n ] ; if ( pos == - 1 ) return false ; return getSum ( n ) == getSum ( pos ) ; } public static void main ( String [ ] args ) { sieve ( ) ; int N = 121 ; if ( isHonakerPrime ( N ) ) System . out . print ( "YesNEW_LINE"); else System . out . print ( "NoNEW_LINE"); } }
Check if Matrix sum is prime or not | Java implementation to check if the sum of matrix is prime or not ; Function to check whether a number is prime or not ; Corner case ; Check from 2 to n - 1 ; Function for to find the sum of the given matrix ; Driver Code
class GFG { static int N = 4 , M = 5 ; static boolean isPrime ( int n ) { if ( n <= 1 ) return false ; for ( int i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) if ( n % i == 0 ) return false ; return true ; } static int takeSum ( int a [ ] [ ] ) { int s = 0 ; for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < M ; j ++ ) s += a [ i ] [ j ] ; return s ; } public static void main ( String [ ] args ) { int a [ ] [ ] = { { 1 , 2 , 3 , 4 , 2 } , { 0 , 1 , 2 , 3 , 34 } , { 0 , 34 , 21 , 12 , 12 } , { 1 , 2 , 3 , 6 , 6 } } ; int sum = takeSum ( a ) ; if ( isPrime ( sum ) ) System . out . print ( " YES " + "NEW_LINE"); else System . out . print ( " NO " + "NEW_LINE"); } }
Sum of sum | Java program to implement the above approach ; Function to find the sum ; Calculate sum - series for every natural number and add them ; Driver code
class GFG { static long sumOfSumSeries ( int N ) { long sum = 0L ; for ( int i = 1 ; i <= N ; i ++ ) { sum = sum + ( i * ( i + 1 ) ) / 2 ; } return sum ; } public static void main ( String [ ] args ) { int N = 5 ; System . out . println ( sumOfSumSeries ( N ) ) ; } }
Sum of sum | Java program to implement the above approach ; Function to find the sum ; Driver code
class GFG { static long sumOfSumSeries ( int n ) { return ( n * ( n + 1 ) * ( n + 2 ) ) / 6 ; } public static void main ( String [ ] args ) { int N = 5 ; System . out . println ( sumOfSumSeries ( N ) ) ; } }
Tetradic Primes | Java implementation to print all Tetradic primes smaller than or equal to N . ; Function to check if the number N having all digits lies in the set ( 0 , 1 , 8 ) ; Function to check if the number N is palindrome ; Function to check if a number N is Tetradic ; Function to generate all primes and checking whether number is Tetradic or not ; Create a boolean array " prime [ 0 . . n ] " and initialize all entries it as true . A value in prime [ i ] will finally be false if i is Not a prime , else true . ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p ; Print all Tetradic prime numbers ; Checking whether the given number is prime Tetradic or not ; Driver Code
import java . util . * ; class GFG { public static boolean isContaindigit ( int n ) { while ( n > 0 ) { if ( ! ( n % 10 == 0 n % 10 == 1 n % 10 == 8 ) ) return false ; n = n / 10 ; } return true ; } public static boolean ispalindrome ( int n ) { String temp = Integer . toString ( n ) ; int l = temp . length ( ) ; for ( int i = 0 ; i < l / 2 ; i ++ ) { if ( temp . charAt ( i ) != temp . charAt ( l - i - 1 ) ) return false ; } return true ; } public static boolean isTetradic ( int n ) { if ( ispalindrome ( n ) && isContaindigit ( n ) ) return true ; return false ; } public static void printTetradicPrimesLessThanN ( int n ) { boolean prime [ ] = new boolean [ n + 1 ] ; Arrays . fill ( prime , true ) ; int p = 2 ; while ( p * p <= n ) { if ( prime [ p ] ) { for ( int i = p * 2 ; i < n + 1 ; i += p ) prime [ i ] = false ; } p += 1 ; } for ( p = 2 ; p < n + 1 ; p ++ ) { if ( prime [ p ] && isTetradic ( p ) ) System . out . print ( p + " ▁ " ) ; } } public static void main ( String [ ] args ) { int n = 1000 ; printTetradicPrimesLessThanN ( n ) ; } }