codeparrot/xlcost-text-to-code huggingface dataset:
Generate a list of n consecutive composite numbers ( An interesting method ) | Java program to print n consecutive composite numbers ; function to find factorial of given number ; Prints n consecutive numbers . ; Driver program to test above function
class GFG { static long factorial ( int n ) { long res = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { res *= i ; } return res ; } static void printNComposite ( int n ) { long fact = factorial ( n + 1 ) ; for ( int i = 2 ; i <= n + 1 ; ++ i ) { System . out . print ( fact + i + " ▁ " ) ; } } public static void main ( String [ ] args ) { int n = 4 ; printNComposite ( n ) ; } }
Frugal Number | Program to check for Frugal number ; Finding primes upto entered number ; Finding primes by Sieve of Eratosthenes method ; If prime [ i ] is not changed , then it is prime ; Update all multiples of p ; Forming array of the prime numbers found ; Returns number of digits in n ; Checking whether a number is Frugal or not ; Finding number of digits in prime factorization of the number ; Exponent for current factor ; Counting number of times this prime factor divides ( Finding exponent ) ; Finding number of digits in the exponent Avoiding exponents of value 1 ; Checking condition for frugal number ; Driver Code
import java . io . * ; import java . util . * ; class GFG { static ArrayList < Long > primes ( long n ) { boolean [ ] prime = new boolean [ ( int ) n + 1 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) prime [ i ] = true ; for ( int i = 2 ; i * i <= n ; i ++ ) { if ( prime [ i ] == true ) { for ( int j = i * 2 ; j <= n ; j += i ) prime [ j ] = false ; } } ArrayList < Long > arr = new ArrayList < Long > ( ) ; for ( int i = 2 ; i < n ; i ++ ) if ( prime [ i ] ) arr . add ( ( long ) i ) ; return arr ; } static int countDigits ( long n ) { long temp = n ; int c = 0 ; while ( temp != 0 ) { temp = temp / 10 ; c ++ ; } return c ; } static boolean frugal ( long n ) { ArrayList < Long > r = primes ( n ) ; long t = n ; long s = 0 ; for ( int i = 0 ; i < r . size ( ) ; i ++ ) { if ( t % r . get ( i ) == 0 ) { long k = 0 ; while ( t % r . get ( i ) == 0 ) { t = t / r . get ( i ) ; k ++ ; } if ( k == 1 ) s = s + countDigits ( r . get ( i ) ) ; else if ( k != 1 ) s = s + countDigits ( r . get ( i ) ) + countDigits ( k ) ; } } return ( countDigits ( n ) > s && s != 0 ) ; } public static void main ( String [ ] args ) { long n = 343 ; if ( frugal ( n ) ) System . out . print ( "A Frugal numberNEW_LINE"); else System . out . print ( "Not a frugal numberNEW_LINE"); } }
N | Java program to find n - th number which is both square and cube . ; Driver code
class GFG { static int nthSquareCube ( int n ) { return n * n * n * n * n * n ; } public static void main ( String [ ] args ) { int n = 5 ; System . out . println ( nthSquareCube ( n ) ) ; } }
Squared triangular number ( Sum of cubes ) | Java program to check if a given number is sum of cubes of natural numbers . ; Function to find if the given number is sum of the cubes of first n natural numbers ; Start adding cubes of the numbers from 1 ; If sum becomes equal to s return n ; Drivers code
class GFG { static int findS ( int s ) { int sum = 0 ; for ( int n = 1 ; sum < s ; n ++ ) { sum += n * n * n ; if ( sum == s ) return n ; } return - 1 ; } public static void main ( String [ ] args ) { int s = 9 ; int n = findS ( s ) ; if ( n == - 1 ) System . out . println ( " - 1" ) ; else System . out . println ( n ) ; } }
Number with even sum of digits | Java program to find n - th Good number . ; Function to find kth good number . ; Find the last digit of n . ; If last digit is between 0 to 4 then return 2 * n . ; If last digit is between 5 to 9 then return 2 * n + 1. ; Driver code
class GFG { static int findKthGoodNo ( int n ) { int lastDig = n % 10 ; if ( lastDig >= 0 && lastDig <= 4 ) return n << 1 ; else return ( n << 1 ) + 1 ; } public static void main ( String [ ] args ) { int n = 10 ; System . out . println ( findKthGoodNo ( n ) ) ; } }
Nicomachu 's Theorem | Java program to verify Nicomachu 's Theorem ; Compute sum of cubes ; Check if sum is equal to given formula . ; driver function
import java . io . * ; class GFG { static void NicomachuTheorum_sum ( int n ) { int sum = 0 ; for ( int k = 1 ; k <= n ; k ++ ) sum += k * k * k ; int triNo = n * ( n + 1 ) / 2 ; if ( sum == triNo * triNo ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void main ( String [ ] args ) { int n = 5 ; NicomachuTheorum_sum ( n ) ; } }
Largest even digit number not greater than N | Java program to print the largest integer not greater than N with all even digits ; function to check if all digits are even of a given number ; iterate for all digits ; if digit is odd ; all digits are even ; function to return the largest number with all digits even ; iterate till we find a number with all digits even ; Driver Code
import java . io . * ; public class GFG { static int checkDigits ( int n ) { while ( n > 0 ) { if ( ( ( n % 10 ) % 2 ) > 0 ) return 0 ; n /= 10 ; } return 1 ; } static int largestNumber ( int n ) { for ( int i = n ; ; i -- ) if ( checkDigits ( i ) > 0 ) return i ; } static public void main ( String [ ] args ) { int N = 23 ; System . out . println ( largestNumber ( N ) ) ; } }
Largest even digit number not greater than N | Java program to print the largest integer not greater than N with all even digits ; function to return the largest number with all digits even ; convert the number to a string for easy operations ; find first odd digit ; if no digit , then N is the answer ; till first odd digit , add all even numbers ; decrease 1 from the odd digit ; add 0 in the rest of the digits ; Driver Code
class GFG { static int largestNumber ( int n ) { String s = " " ; int duplicate = n ; while ( n > 0 ) { s = ( char ) ( n % 10 + 48 ) + s ; n /= 10 ; } int index = - 1 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( ( ( ( int ) ( s . charAt ( i ) - '0' ) % 2 ) & 1 ) > 0 ) { index = i ; break ; } } if ( index == - 1 ) return duplicate ; int num = 0 ; for ( int i = 0 ; i < index ; i ++ ) num = num * 10 + ( int ) ( s . charAt ( i ) - '0' ) ; num = num * 10 + ( ( int ) s . charAt ( index ) - ( int ) ( '0' ) - 1 ) ; for ( int i = index + 1 ; i < s . length ( ) ; i ++ ) num = num * 10 + 8 ; return num ; } public static void main ( String [ ] args ) { int N = 24578 ; System . out . println ( largestNumber ( N ) ) ; } }
Number of digits in 2 raised to power n | Java program to find number of digits in 2 ^ n ; Function to find number of digits in 2 ^ n ; Driver Code
import java . util . * ; class Gfg { static int countDigits ( int n ) { return ( int ) ( n * Math . log10 ( 2 ) + 1 ) ; } public static void main ( String args [ ] ) { int n = 5 ; System . out . println ( countDigits ( n ) ) ; } }
Smallest even digits number not less than N | Java program to print the smallest integer not less than N with all even digits ; function to check if all digits are even of a given number ; iterate for all digits ; if digit is odd ; all digits are even ; function to return the smallest number with all digits even ; iterate till we find a number with all digits even ; Driver Code
class GFG { static int check_digits ( int n ) { while ( n != 0 ) { if ( ( n % 10 ) % 2 != 0 ) return 0 ; n /= 10 ; } return 1 ; } static int smallest_number ( int n ) { for ( int i = n ; ; i ++ ) if ( check_digits ( i ) != 0 ) return i ; } public static void main ( String [ ] args ) { int N = 2397 ; System . out . println ( smallest_number ( N ) ) ; } }
Smallest triangular number larger than p | Java code to find the bucket to choose for picking flowers out of it ; Driver code
import java . lang . System . * ; class GFG { static int findBucketNo ( int p ) { return ( int ) Math . ceil ( ( Math . sqrt ( 8 * p + 1 ) - 1 ) / 2 ) ; } public static void main ( String [ ] args ) { int p = 10 ; System . out . println ( findBucketNo ( p ) ) ; } }
LCM of factorial and its neighbors | Java program to calculate the LCM of N ! and its neighbor ( N - 1 ) ! and ( N + 1 ) ! ; function to calculate the factorial ; returning the factorial of the largest number in the given three consecutive numbers ; Driver code
import java . io . * ; class GFG { static int factorial ( int n ) { if ( n == 0 ) return 1 ; return n * factorial ( n - 1 ) ; } static int LCMOfNeighbourFact ( int n ) { return factorial ( n + 1 ) ; } public static void main ( String args [ ] ) { int N = 5 ; System . out . println ( LCMOfNeighbourFact ( N ) ) ; } }
Expressing factorial n as sum of consecutive numbers | Java program to count number of ways we can express a factorial as sum of consecutive numbers ; sieve of Eratosthenes to compute the prime numbers ; Store all prime numbers ; function to calculate the largest power of a prime in a number ; Modular multiplication to avoid the overflow of multiplication Please see below for details https : www . geeksforgeeks . org / how - to - avoid - overflow - in - modular - multiplication / ; Returns count of ways to express n ! as sum of consecutives . ; We skip 2 ( First prime ) as we need to consider only odd primes ; compute the largest power of prime ; if the power of current prime number is zero in N ! , power of primes greater than current prime number will also be zero , so break out from the loop ; multiply the result at every step ; subtract 1 to exclude the case of 1 being an odd divisor ; Driver function
import java . util . * ; class GFG { static int MAX = 50002 ; static ArrayList < Integer > primes = new ArrayList < Integer > ( ) ; public static void sieve ( ) { boolean isPrime [ ] = new boolean [ MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) isPrime [ i ] = true ; for ( int p = 2 ; p * p < MAX ; p ++ ) { if ( isPrime [ p ] == true ) { for ( int i = p * 2 ; i < MAX ; i += p ) isPrime [ i ] = false ; } } for ( int p = 2 ; p < MAX ; p ++ ) if ( isPrime [ p ] == true ) primes . add ( p ) ; } public static int power ( int x , int y ) { int count = 0 ; int z = y ; while ( x >= z ) { count += ( x / z ) ; z *= y ; } return count ; } public static int modMult ( int a , int b , int mod ) { int res = 0 ; a = a % mod ; while ( b > 0 ) { if ( b % 2 == 1 ) res = ( res + a ) % mod ; a = ( a * 2 ) % mod ; b /= 2 ; } return res % mod ; } public static int countWays ( int n , int m ) { int ans = 1 ; for ( int i = 1 ; i < primes . size ( ) ; i ++ ) { int powers = power ( n , primes . get ( i ) ) ; if ( powers == 0 ) break ; ans = modMult ( ans , powers + 1 , m ) % m ; } if ( ( ( ans - 1 ) % m ) < 0 ) return ( ans - 1 + m ) % m ; else return ( ans - 1 ) % m ; } public static void main ( String [ ] args ) { sieve ( ) ; int n = 4 , m = 7 ; System . out . println ( countWays ( n , m ) ) ; } }
Check if the given two numbers are friendly pair or not | Java code to check if the given two number are friendly pair or not . ; Returns sum of all factors of n . ; Traversing through all prime factors . ; THE BELOW STATEMENT MAKES IT BETTER THAN ABOVE METHOD AS WE REDUCE VALUE OF n . ; This condition is to handle the case when n is a prime number greater than 2. ; Function to return gcd of a and b ; Function to check if the given two number are friendly pair or not . ; Finding the sum of factors of n and m ; finding gcd of n and sum of its factors . ; finding gcd of m and sum of its factors . ; checking is numerator and denominator of abundancy index of both number are equal or not . ; driver code
class GFG { static int sumofFactors ( int n ) { int res = 1 ; for ( int i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { int count = 0 , curr_sum = 1 ; int curr_term = 1 ; while ( n % i == 0 ) { count ++ ; n = n / i ; curr_term *= i ; curr_sum += curr_term ; } res *= curr_sum ; } if ( n >= 2 ) res *= ( 1 + n ) ; return res ; } static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static boolean checkFriendly ( int n , int m ) { int sumFactors_n = sumofFactors ( n ) ; int sumFactors_m = sumofFactors ( m ) ; int gcd_n = gcd ( n , sumFactors_n ) ; int gcd_m = gcd ( m , sumFactors_m ) ; if ( n / gcd_n == m / gcd_m && sumFactors_n / gcd_n == sumFactors_m / gcd_m ) return true ; else return false ; } public static void main ( String [ ] args ) { int n = 6 , m = 28 ; if ( checkFriendly ( n , m ) ) System . out . print ( "YesNEW_LINE"); else System . out . print ( "NoNEW_LINE"); } }
Find n | Java program to find n - th Fortunate number ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Function to Find primorial of order n ( product of first n prime numbers ) . ; Function to find next prime number greater than n ; Note that difference ( or m ) should be greater than 1. ; loop continuously until isPrime returns true for a number above n ; Ignoring the prime number that is 1 greater than n ; Returns n - th Fortunate number ; Driver function
import java . lang . * ; import java . util . * ; class GFG { public 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 ; } public static int primorial ( int n ) { int p = 2 ; n -- ; for ( int i = 3 ; n != 0 ; i ++ ) { if ( isPrime ( i ) == true ) { p = p * i ; n -- ; } i ++ ; } return p ; } public static int findNextPrime ( int n ) { int nextPrime = n + 2 ; while ( true ) { if ( isPrime ( nextPrime ) == true ) break ; nextPrime ++ ; } return nextPrime ; } public static int fortunateNumber ( int n ) { int p = primorial ( n ) ; return findNextPrime ( p ) - p ; } public static void main ( String [ ] args ) { int n = 5 ; System . out . println ( fortunateNumber ( n ) ) ; } }
Probability for three randomly chosen numbers to be in AP | Java program to find probability that 3 randomly chosen numbers form AP . ; function to calculate probability ; Driver code to run above function
class GFG { static double procal ( int n ) { return ( 3.0 * n ) / ( 4.0 * ( n * n ) - 1 ) ; } public static void main ( String arg [ ] ) { int a [ ] = { 1 , 2 , 3 , 4 , 5 } ; int n = a . length ; System . out . print ( Math . round ( procal ( n ) * 1000000.0 ) / 1000000.0 ) ; } }
Fermat 's Last Theorem | Java program to verify fermat 's last theorem for a given range and n. ; Check if there exists a triplet such that a ^ n + b ^ n = c ^ n ; Driver code
import java . io . * ; class GFG { static void testSomeNumbers ( int limit , int n ) { if ( n < 3 ) return ; for ( int a = 1 ; a <= limit ; a ++ ) for ( int b = a ; b <= limit ; b ++ ) { int pow_sum = ( int ) ( Math . pow ( a , n ) + Math . pow ( b , n ) ) ; double c = Math . pow ( pow_sum , 1.0 / n ) ; int c_pow = ( int ) Math . pow ( ( int ) c , n ) ; if ( c_pow == pow_sum ) { System . out . println ( " Count ▁ example ▁ found " ) ; return ; } } System . out . println ( " No ▁ counter ▁ example ▁ within ▁ given " + " ▁ range ▁ and ▁ data " ) ; } public static void main ( String [ ] args ) { testSomeNumbers ( 12 , 5 ) ; } }
Product of given N fractions in reduced form | Java program to find product of N fractions in reduced form . ; Function to return gcd of a and b ; Print the Product of N fraction in Reduced Form . ; finding the product of all N numerators and denominators . ; Finding GCD of new numerator and denominator ; Converting into reduced form . ; Driven Program
import java . io . * ; class GFG { static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static void productReduce ( int n , int num [ ] , int den [ ] ) { int new_num = 1 , new_den = 1 ; for ( int i = 0 ; i < n ; i ++ ) { new_num *= num [ i ] ; new_den *= den [ i ] ; } int GCD = gcd ( new_num , new_den ) ; new_num /= GCD ; new_den /= GCD ; System . out . println ( new_num + " / " + new_den ) ; } public static void main ( String [ ] args ) { int n = 3 ; int num [ ] = { 1 , 2 , 5 } ; int den [ ] = { 2 , 1 , 6 } ; productReduce ( n , num , den ) ; } }
Find value of ( n ^ 1 + n ^ 2 + n ^ 3 + n ^ 4 ) mod 5 for given n | Java code to finding the value of f ( n ) mod 5 for given n . ; function for f ( n ) mod 5 ; if n % 5 == 1 return 4 ; else return 0 ; Driver program
import java . io . * ; class GFG { static int fnMod ( int n ) { if ( n % 5 == 1 ) return 4 ; else return 0 ; } public static void main ( String [ ] args ) { int n = 10 ; System . out . println ( fnMod ( n ) ) ; n = 11 ; System . out . println ( fnMod ( n ) ) ; } }
Recursive sum of digits of a number formed by repeated appends | Java program to find Sum of digits of a number formed by repeating a number X number of times until sum become single digit . ; return single digit sum of a number . ; Returns recursive sum of digits of a number formed by repeating a number X number of times until sum become single digit . ; Driver program
class GFG { static int digSum ( int n ) { if ( n == 0 ) return 0 ; return ( n % 9 == 0 ) ? 9 : ( n % 9 ) ; } static int repeatedNumberSum ( int n , int x ) { int sum = x * digSum ( n ) ; return digSum ( sum ) ; } public static void main ( String [ ] args ) { int n = 24 , x = 3 ; System . out . println ( repeatedNumberSum ( n , x ) ) ; } }
Sum of n digit numbers divisible by a given number | Simple Java program to sum of n digit divisible numbers . ; Returns sum of n digit numbers divisible by ' number ' ; compute the first and last term ; sum of number which having n digit and divisible by number ; Driver code
import java . io . * ; class GFG { static int totalSumDivisibleByNum ( int n , int number ) { int firstnum = ( int ) Math . pow ( 10 , n - 1 ) ; int lastnum = ( int ) Math . pow ( 10 , n ) ; int sum = 0 ; for ( int i = firstnum ; i < lastnum ; i ++ ) if ( i % number == 0 ) sum += i ; return sum ; } public static void main ( String [ ] args ) { int n = 3 , num = 7 ; System . out . println ( totalSumDivisibleByNum ( n , num ) ) ; } }
Extended Midy 's theorem | Java program to demonstrate extended Midy 's theorem ; Returns repeating sequence of a fraction . If repeating sequence doesn 't exits, then returns -1 ; Create a map to store already seen remainders remainder is used as key and its position in result is stored as value . Note that we need position for cases like 1 / 6. In this case , the recurring sequence doesn 't start from first  remainder.  ; Find first remainder ; Keep finding remainder until either remainder becomes 0 or repeats ; Store this remainder ; Multiply remainder with 10 ; Append rem / denr to result ; Update remainder ; Checks whether a number is prime or not ; If all conditions are met , it proves Extended Midy 's theorem ; Dividing repeated part into m parts ; Computing sum of parts . ; Checking for Extended Midy ; Driver code
import java . util . * ; class GFG { static String fractionToDecimal ( int numerator , int denominator ) { String res = " " ; HashMap < Integer , Integer > mp = new HashMap < > ( ) ; int rem = numerator % denominator ; while ( ( rem != 0 ) && ! mp . containsKey ( rem ) ) { mp . put ( rem , res . length ( ) ) ; rem = rem * 10 ; int res_part = rem / denominator ; res += res_part + " " ; rem = rem % denominator ; } return ( rem == 0 ) ? " - 1" : res . substring ( mp . get ( rem ) ) ; } static boolean isPrime ( int n ) { for ( int i = 2 ; i <= n / 2 ; i ++ ) if ( n % i == 0 ) return false ; return true ; } static void ExtendedMidys ( String str , int n , int m ) { if ( ! isPrime ( n ) ) { System . out . print ( " Denominator ▁ is ▁ not ▁ prime , ▁ " + " thus ▁ Extended ▁ Midy ' s ▁ theorem ▁ " + " is ▁ not ▁ applicable " ) ; return ; } int l = str . length ( ) ; int part1 = 0 , part2 = 0 ; if ( l % 2 == 0 && l % m == 0 ) { int [ ] part = new int [ m ] ; int sum = 0 , res = 0 ; for ( int i = 0 ; i < l ; i ++ ) { int var = i / m ; part [ var ] = part [ var ] * 10 + ( str . charAt ( i ) - '0' ) ; } for ( int i = 0 ; i < m ; i ++ ) { sum = sum + part [ i ] ; System . out . print ( part [ i ] + " ▁ " ) ; } System . out . println ( ) ; res = ( int ) Math . pow ( 10 , m ) - 1 ; if ( sum % res == 0 ) System . out . print ( " Extended ▁ Midy ' s ▁ " + " theorem ▁ holds ! " ) ; else System . out . print ( " Extended ▁ Midy ' s ▁ " + " theorem ▁ doesn ' t ▁ hold ! " ) ; } else if ( l % 2 != 0 ) { System . out . print ( " The ▁ repeating ▁ decimal ▁ is ▁ of ▁ " + " odd ▁ length ▁ thus ▁ Extended ▁ Midy ' s ▁ " + " theorem ▁ is ▁ not ▁ applicable " ) ; } else if ( l % m != 0 ) { System . out . print ( " The ▁ repeating ▁ decimal ▁ can ▁ " + " not ▁ be ▁ divided ▁ into ▁ m ▁ digits " ) ; } } public static void main ( String [ ] args ) { int numr = 1 , denr = 17 , m = 4 ; String res = fractionToDecimal ( numr , denr ) ; if ( res == " - 1" ) System . out . print ( " The ▁ fraction ▁ does ▁ not ▁ " + " have ▁ repeating ▁ decimal " ) ; else { System . out . println ( " Repeating ▁ decimal ▁ = ▁ " + res ) ; ExtendedMidys ( res , denr , m ) ; } } }
Count n digit numbers divisible by given number | Simple Java program to count n digit divisible numbers . ; Returns count of n digit numbers divisible by ' number ' ; compute the first and last term ; count total number of which having n digit and divisible by number ; Driver code
import java . io . * ; class GFG { static int numberofterm ( int n , int number ) { int firstnum = ( int ) Math . pow ( 10 , n - 1 ) ; int lastnum = ( int ) Math . pow ( 10 , n ) ; int count = 0 ; for ( int i = firstnum ; i < lastnum ; i ++ ) if ( i % number == 0 ) count ++ ; return count ; } public static void main ( String [ ] args ) { int n = 3 , num = 7 ; System . out . println ( numberofterm ( n , num ) ) ; } }
N | Java program to find N - th term in George Cantor set of rational number ; let i = numerator ; let j = denominator ; to keep the check of no . of terms ; loop till k is not equal to n ; check if k is already equal to N then the first term is the required rational number ; loop for traversing from right to left downwards diagonally ; loop for traversing from left to right upwards diagonally ; Driver code
import java . io . * ; class GFG { static void georgeCantor ( int n ) { int i = 1 ; int j = 1 ; int k = 1 ; while ( k < n ) { j ++ ; k ++ ; if ( k == n ) break ; while ( j > 1 && k < n ) { i ++ ; j -- ; k ++ ; } if ( k == n ) break ; i ++ ; k ++ ; if ( k == n ) break ; while ( i > 1 && k < n ) { i -- ; j ++ ; k ++ ; } } System . out . println ( " N - th ▁ term ▁ : ▁ " + i + " / " + j ) ; } public static void main ( String [ ] args ) { int n = 15 ; georgeCantor ( n ) ; } }
Number is divisible by 29 or not | Java program to demonstrate above method to check divisibility by 29. ; Returns true if n is divisible by 29 else returns false . ; add the lastdigit * 3 to renaming number until number comes only 2 digit ; return true if number is divisible by 29 another ; Driver code
import java . io . * ; class GFG { static boolean isDivisible ( long n ) { while ( n / 100 > 0 ) { int last_digit = ( int ) n % 10 ; n /= 10 ; n += last_digit * 3 ; } return ( n % 29 == 0 ) ; } public static void main ( String [ ] args ) { long n = 348 ; if ( isDivisible ( n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }