"Sum of largest prime factor of each number less than equal to n | function to find sum of largest prime factor of each number less than equal to n ; Create an integer array " prime [ 0 . . n ] " and initialize all entries of it as 0. A value in prime [ i ] will finally be 0 if ' i ' is a prime , else it will contain the largest prime factor of ' i ' . ; If prime [ p ] is '0' , then it is a prime number ; Update all multiples of p ; Sum up the largest prime factor of all the numbers ; if ' p ' is a non - prime number then prime [ p ] gives its largesr prime factor ; ' p ' is a prime number ; required sum ; Driver program to test above"
How can the above be solved in PHP?

< ? php function sumOfLargePrimeFactor ( $ n ) { $ prime = array_fill ( 0 , $ n + 1 , 0 ) ; $ sum = 0 ; $ max = ( int ) ( $ n / 2 ) ; for ( $ p = 2 ; $ p <= $ max ; $ p ++ ) { if ( $ prime [ $ p ] == 0 ) { for ( $ i = $ p * 2 ; $ i <= $ n ; $ i += $ p ) $ prime [ $ i ] = $ p ; } } for ( $ p = 2 ; $ p <= $ n ; $ p ++ ) { if ( $ prime [ $ p ] ) $ sum += $ prime [ $ p ] ; else $ sum += $ p ; } return $ sum ; } $ n = 12 ; echo " Sum = " ? >


"Sum of multiples of a number up to N | Function for calculating sum of multiples of a upto N ; Number of multiples ; sum of first m natural numbers ; sum of multiples ; Driver code"
How can the above be solved in PHP?

< ? php function calculate_sum ( $ a , $ N ) { $ m = $ N / $ a ; $ sum = $ m * ( $ m + 1 ) / 2 ; $ ans = $ a * $ sum ; return $ ans ; } $ a = 7 ; $ N = 49 ; echo " Sum ▁ of ▁ multiples ▁ of ▁ " . $ a , " ▁ up ▁ to ▁ " . $ N . " ▁ = ▁ " . calculate_sum ( $ a , $ N ) ; ? >


"Sum of series with alternate signed squares of AP | function to calculate series sum ; Driver Code"
How can the above be solved in PHP?


"Sum of series with alternate signed squares of AP | function to calculate series sum ; Driver code"
How can the above be solved in PHP?


"Sum of the first N terms of the series 2 , 10 , 30 , 68 , ... . | Function to calculate the sum ; number of terms to be included in the sum ; find the Sum"
How can the above be solved in PHP?

< ? php function calculateSum ( $ n ) { return $ n * ( $ n + 1 ) / 2 + pow ( ( $ n * ( $ n + 1 ) / 2 ) , 2 ) ; } $ n = 3 ; echo " Sum = " ? >


"Taxicab Numbers | PHP implementation to print first N Taxicab ( 2 ) numbers : ; Starting from 1 , check every number if it is Taxicab until count reaches N . ; Try all possible pairs ( j , k ) whose cube sums can be i . ; Taxicab ( 2 ) found ; Driver code"
How can the above be solved in PHP?


"Total position where king can reach on a chessboard in exactly M moves | Set 2 | Function to return the count of squares that can be visited by king in m moves ; To store the count of squares ; Check all squares of the chessboard ; Check if square ( i , j ) is at a distance <= m units from king 's current position ; Return count of squares ; Driver code"
How can the above be solved in PHP?

< ? php function countSquares ( $ r , $ c , $ m ) { $ squares = 0 ; for ( $ i = 1 ; $ i <= 8 ; $ i ++ ) { for ( $ j = 1 ; $ j <= 8 ; $ j ++ ) { if ( max ( abs ( $ i - $ r ) , abs ( $ j - $ c ) ) <= $ m ) $ squares ++ ; } } return $ squares ; } $ r = 4 ; $ c = 4 ; $ m = 1 ; echo countSquares ( $ r , $ c , $ m ) ; ? >


"Transform the string | Function to change character 's case ; If character is lowercase change to uppercase ; If character is uppercase change to lowercase ; Function to delete vowels ; If character is consonant ; Function to insert " # " ; If character is not special ; Function to transform string ; Driver Code ; Calling function"
How can the above be solved in PHP?


"Trick for modular division ( ( x1 * x2 ... . xn ) / b ) mod ( m ) |"
How can the above be solved in PHP?


"Trinomial Triangle | Function to find the trinomial triangle value . ; base case ; base case ; recursive step . ; Function to print Trinomial Triangle of height n . ; printing n rows . ; printing first half of triangle ; printing second half of triangle . ; Driver Code"
How can the above be solved in PHP?

 < ? php function TrinomialValue ( $ n , $ k ) { if ( $ n == 0 && $ k == 0 ) return 1 ; if ( $ k < - $ n $ k > $ n ) return 0 ; return TrinomialValue ( $ n - 1 , $ k - 1 ) + TrinomialValue ( $ n - 1 , $ k ) + TrinomialValue ( $ n - 1 , $ k + 1 ) ; } function printTrinomial ( $ n ) { for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { for ( $ j = - $ i ; $ j <= 0 ; $ j ++ ) echo TrinomialValue ( $ i , $ j ) , " ▁ " ; for ( $ j = 1 ; $ j <= $ i ; $ j ++ ) echo TrinomialValue ( $ i , $ j ) , " ▁ " ; echo "
 " ; } } $ n = 4 ; printTrinomial ( $ n ) ; ? >


"Trinomial Triangle | PHP Program to print trinomial triangle . ; Function to find the trinomial triangle value . ; Using property of trinomial triangle . ; If value already calculated , return that . ; base case ; base case ; recursive step and storing the value . ; Function to print Trinomial Triangle of height n . ; printing n rows . ; printing first half of triangle ; printing second half of triangle . ; Driven Code"
How can the above be solved in PHP?

 < ? php $ MAX = 10 ; function TrinomialValue ( $ dp , $ n , $ k ) { if ( $ k < 0 ) $ k = - $ k ; if ( $ dp [ $ n ] [ $ k ] != 0 ) return $ dp [ $ n ] [ $ k ] ; if ( $ n == 0 && $ k == 0 ) return 1 ; if ( $ k < - $ n $ k > $ n ) return 0 ; return ( $ dp [ $ n ] [ $ k ] = TrinomialValue ( $ dp , $ n - 1 , $ k - 1 ) + TrinomialValue ( $ dp , $ n - 1 , $ k ) + TrinomialValue ( $ dp , $ n - 1 , $ k + 1 ) ) ; } function printTrinomial ( $ n ) { global $ MAX ; $ dp ; for ( $ i = 0 ; $ i < $ MAX ; $ i ++ ) for ( $ j = 0 ; $ j < $ MAX ; $ j ++ ) $ dp [ $ i ] [ $ j ] = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { for ( $ j = - $ i ; $ j <= 0 ; $ j ++ ) echo TrinomialValue ( $ dp , $ i , $ j ) . " ▁ " ; for ( $ j = 1 ; $ j <= $ i ; $ j ++ ) echo TrinomialValue ( $ dp , $ i , $ j ) . " ▁ " ; echo "
 " ; } } $ n = 4 ; printTrinomial ( $ n ) ; ? >


"Undulating numbers | PHP program to check whether a number is undulating or not ; Considering the definition with restriction that there should be at least 3 digits ; Check if all alternate digits are same or not . ; Driver code"
How can the above be solved in PHP?

< ? php function isUndulating ( $ n ) { if ( strlen ( $ n ) <= 2 ) return false ; for ( $ i = 2 ; $ i < strlen ( $ n ) ; $ i ++ ) if ( $ n [ $ i - 2 ] != $ n [ $ i ] ) false ; return true ; } $ n = "1212121" ; if ( isUndulating ( $ n ) ) echo ( " Yes " ) ; else echo ( " No " ) ; ? >


"Ways to Remove Edges from a Complete Graph to make Odd Edges | Function to return the number of ways to remove edges from the graph so that odd number of edges are left in the graph ; Total number of edges ; Driver code"
How can the above be solved in PHP?

< ? php function countWays ( $ N ) { $ E = ( $ N * ( $ N - 1 ) ) / 2 ; if ( $ N == 1 ) return 0 ; return ( int ) pow ( 2 , $ E - 1 ) ; } $ N = 4 ; echo ( countWays ( $ N ) ) ; ? >


"Ways to multiply n elements with an associative operation | Function to find the required factorial ; Function to find nCr ; function to find the number of ways ; Driver code"
How can the above be solved in PHP?

< ? php function fact ( $ n ) { if ( $ n == 0 $ n == 1 ) return 1 ; $ ans = 1 ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) $ ans = $ ans * $ i ; return $ ans ; } function nCr ( $ n , $ r ) { $ Nr = $ n ; $ Dr = 1 ; $ ans = 1 ; for ( $ i = 1 ; $ i <= $ r ; $ i ++ ) { $ ans = ( $ ans * $ Nr ) / ( $ Dr ) ; $ Nr -- ; $ Dr ++ ; } return $ ans ; } function solve ( $ n ) { $ N = 2 * $ n - 2 ; $ R = $ n - 1 ; return nCr ( $ N , $ R ) * fact ( $ n - 1 ) ; } $ n = 6 ; echo solve ( $ n ) ; ? >


"Ways to write N as sum of two or more positive integers | Set | Function to find the number of partitions of N ; Base case ; Driver Code"
How can the above be solved in PHP?


"Write a program to reverse digits of a number | PHP program to reverse digits of a number ; Recursive function to reverse digits of num ; Driver Code"
How can the above be solved in PHP?

< ? php $ rev_num = 0 ; $ base_pos = 1 ; function reversDigits ( $ num ) { global $ rev_num ; global $ base_pos ; if ( $ num > 0 ) { reversDigits ( ( int ) ( $ num / 10 ) ) ; $ rev_num += ( $ num % 10 ) * $ base_pos ; $ base_pos *= 10 ; } return $ rev_num ; } $ num = 4562 ; echo " Reverse ▁ of ▁ no . ▁ is ▁ " , reversDigits ( $ num ) ; ? >


"gOOGLE cASE of a given sentence | Function to remove spaces and convert into camel case ; check for spaces in the sentence ; conversion into upper case ; If not space , copy character ; return string to main ; Driver Code"
How can the above be solved in PHP?

< ? php function convert ( $ s ) { $ n = strlen ( $ s ) ; $ s [ 0 ] = strtolower ( $ s [ 0 ] ) ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) { if ( $ s [ $ i ] == ' ▁ ' && $ i < $ n ) { $ s [ $ i + 1 ] = strtolower ( $ s [ $ i + 1 ] ) ; $ i ++ ; } else $ s [ $ i ] = strtoupper ( $ s [ $ i ] ) ; } return $ s ; } $ str = " I ▁ get ▁ intern ▁ at ▁ geeksforgeeks " ; echo ( convert ( $ str ) ) ; ? >


"gOOGLE cASE of a given sentence | PHP program to convert a sentence to gOOGLE cASE . ; empty strings ; convert input to upper case ; checki if character is not a space and adding it to $w ; converting first character to lower case and subsequent initial letter of another word to lower case ; Driver code"
How can the above be solved in PHP?

< ? php function convert ( $ str ) { $ w = " " ; $ z = " " ; $ str = strtoupper ( $ str ) . " ▁ " ; for ( $ i = 0 ; $ i < strlen ( $ str ) ; $ i ++ ) { $ ch = $ str [ $ i ] ; if ( $ ch != ' ▁ ' ) $ w = $ w . $ ch ; else { $ z = $ z . strtolower ( $ w [ 0 ] ) . substr ( $ w , 1 ) . " ▁ " ; $ w = " " ; } } return $ z ; } $ str = " I ▁ got ▁ intern ▁ at ▁ geeksforgeeks " ; echo ( convert ( $ str ) ) ; ? >