codeparrot/xlcost-text-to-code huggingface dataset:
Remove an element to maximize the GCD of the given array | C # implementation of the above approach ; Recursive function to return gcd of a and b ; Function to return the maximized gcd after removing a single element from the given array ; Prefix and Suffix arrays ; Single state dynamic programming relation for storing gcd of first i elements from the left in Prefix [ i ] ; Initializing Suffix array ; Single state dynamic programming relation for storing gcd of all the elements having greater than or equal to i in Suffix [ i ] ; If first or last element of the array has to be removed ; If any other element is replaced ; Return the maximized gcd ; Driver code
using System ; class GFG { static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } static int MaxGCD ( int [ ] a , int n ) { int [ ] Prefix = new int [ n + 2 ] ; int [ ] Suffix = new int [ n + 2 ] ; Prefix [ 1 ] = a [ 0 ] ; for ( int i = 2 ; i <= n ; i += 1 ) { Prefix [ i ] = gcd ( Prefix [ i - 1 ] , a [ i - 1 ] ) ; } Suffix [ n ] = a [ n - 1 ] ; for ( int i = n - 1 ; i >= 1 ; i -= 1 ) { Suffix [ i ] = gcd ( Suffix [ i + 1 ] , a [ i - 1 ] ) ; } int ans = Math . Max ( Suffix [ 2 ] , Prefix [ n - 1 ] ) ; for ( int i = 2 ; i < n ; i += 1 ) { ans = Math . Max ( ans , gcd ( Prefix [ i - 1 ] , Suffix [ i + 1 ] ) ) ; } return ans ; } static public void Main ( ) { int [ ] a = { 14 , 17 , 28 , 70 } ; int n = a . Length ; Console . Write ( MaxGCD ( a , n ) ) ; } }
Maximum subarray sum by flipping signs of at most K array elements | C # implementation of the approach ; Function to find the maximum subarray sum with flips starting from index i ; If the number of flips have exceeded ; Complete traversal ; If the state has previously been visited ; Initially ; Use Kadane 's algorithm and call two states ; Memoize the answer and return it ; Utility function to call flips from index and return the answer ; Create DP array int dp [ n ] [ k + 1 ] ; ; Iterate and call recursive function from every index to get the maximum subarray sum ; corner case ; Driver Code
using System ; using System . Linq ; class GFG { static int right = 2 ; static int left = 4 ; static int [ , ] dp = new int [ left + 1 , right + 1 ] ; static int findSubarraySum ( int ind , int flips , int n , int [ ] a , int k ) { if ( flips > k ) return - ( int ) 1e9 ; if ( ind == n ) return 0 ; if ( dp [ ind , flips ] != - 1 ) return dp [ ind , flips ] ; int ans = 0 ; ans = Math . Max ( 0 , a [ ind ] + findSubarraySum ( ind + 1 , flips , n , a , k ) ) ; ans = Math . Max ( ans , - a [ ind ] + findSubarraySum ( ind + 1 , flips + 1 , n , a , k ) ) ; return dp [ ind , flips ] = ans ; } static int findMaxSubarraySum ( int [ ] a , int n , int k ) { for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < k + 1 ; j ++ ) dp [ i , j ] = - 1 ; int ans = - ( int ) 1e9 ; for ( int i = 0 ; i < n ; i ++ ) ans = Math . Max ( ans , findSubarraySum ( i , 0 , n , a , k ) ) ; if ( ans == 0 && k == 0 ) return a . Max ( ) ; return ans ; } static void Main ( ) { int [ ] a = { - 1 , - 2 , - 100 , - 10 } ; int n = a . Length ; int k = 1 ; Console . WriteLine ( findMaxSubarraySum ( a , n , k ) ) ; } }
Find the sum of first N odd Fibonacci numbers | C # program to Find the sum of first N odd Fibonacci numbers ; Function to calculate sum of first N odd Fibonacci numbers ; base values ; Driver code
using System ; public class GFG { static int mod = 1000000007 ; static int sumOddFibonacci ( int n ) { int [ ] Sum = new int [ n + 1 ] ; Sum [ 0 ] = 0 ; Sum [ 1 ] = 1 ; Sum [ 2 ] = 2 ; Sum [ 3 ] = 5 ; Sum [ 4 ] = 10 ; Sum [ 5 ] = 23 ; for ( int i = 6 ; i <= n ; i ++ ) { Sum [ i ] = ( ( Sum [ i - 1 ] + ( 4 * Sum [ i - 2 ] ) % mod - ( 4 * Sum [ i - 3 ] ) % mod + mod ) % mod + ( Sum [ i - 4 ] - Sum [ i - 5 ] + mod ) % mod ) % mod ; } return Sum [ n ] ; } static public void Main ( ) { int n = 6 ; Console . WriteLine ( sumOddFibonacci ( n ) ) ; }
Minimize the total number of teddies to be distributed | C # implementation of the above approach ; Initializing one tablet for each student ; if left adjacent is having higher marks review and change all the dp values assigned before until assigned dp values are found wrong according to given constrains ; if right adjacent is having higher marks add one in dp of left adjacent and assign to right one ; Driver Code ; n number of students ; marks of students ; solution of problem
using System ; class GFG { public static long fun ( int [ ] marks , int n ) { long [ ] dp = new long [ n ] ; long temp ; for ( int i = 0 ; i < n ; i ++ ) dp [ i ] = 1 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( marks [ i ] > marks [ i + 1 ] ) { temp = i ; while ( true ) { if ( ( marks [ temp ] > marks [ temp + 1 ] ) && temp >= 0 ) { if ( dp [ temp ] > dp [ temp + 1 ] ) { temp -= 1 ; continue ; } else { dp [ temp ] = dp [ temp + 1 ] + 1 ; temp -= 1 ; } } else break ; } } else if ( marks [ i ] < marks [ i + 1 ] ) dp [ i + 1 ] = dp [ i ] + 1 ; } long sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += dp [ i ] ; return sum ; } static void Main ( ) { int n = 6 ; int [ ] marks = new int [ ] { 1 , 4 , 5 , 2 , 2 , 1 } ; Console . Write ( fun ( marks , n ) ) ; } }
Number of ways to reach Nth floor by taking at | C # program to reach N - th stair by taking a maximum of K leap ; elements of combo [ ] stores the no . of possible ways to reach it by all combinations of k leaps or less ; assuming leap 0 exist and assigning its value to 1 for calculation ; loop to iterate over all possible leaps upto k ; ; in this loop we count all possible leaps to reach the jth stair with the help of ith leap or less ; if the leap is not more than the i - j ; calculate the value and store in combo [ j ] to reuse it for next leap calculation for the jth stair ; returns the no of possible number of leaps to reach the top of building of n stairs ; Driver Code ; N i the no of total stairs K is the value of the greatest leap
using System ; class GFG { static int solve ( int N , int K ) { int [ ] combo ; combo = new int [ 50 ] ; combo [ 0 ] = 1 ; for ( int i = 1 ; i <= K ; i ++ ) { for ( int j = 0 ; j <= N ; j ++ ) { if ( j >= i ) { combo [ j ] += combo [ j - i ] ; } } } return combo [ N ] ; } public static void Main ( ) { int N = 29 ; int K = 5 ; Console . WriteLine ( solve ( N , K ) ) ; solve ( N , K ) ; } }
Find the Longest Increasing Subsequence in Circular manner | C # implementation to find LIS in circular way ; Utility method to find LIS using Dynamic programming ; Initialize LIS values for all indexes ; Compute optimized LIS values in bottom up manner ; Set j on the basis of current window i . e . first element of the current window ; Pick maximum of all LIS values ; Function to find Longest Increasing subsequence in Circular manner ; Make a copy of given array by appending same array elements to itself ; Perform LIS for each window of size n ; Driver method
using System ; class Test { static int computeLIS ( int [ ] circBuff , int start , int end , int n ) { int [ ] LIS = new int [ n + end - start ] ; for ( int i = start ; i < end ; i ++ ) LIS [ i ] = 1 ; for ( int i = start + 1 ; i < end ; i ++ ) for ( int j = start ; j < i ; j ++ ) if ( circBuff [ i ] > circBuff [ j ] && LIS [ i ] < LIS [ j ] + 1 ) LIS [ i ] = LIS [ j ] + 1 ; int res = int . MinValue ; for ( int i = start ; i < end ; i ++ ) res = Math . Max ( res , LIS [ i ] ) ; return res ; } static int LICS ( int [ ] arr , int n ) { int [ ] circBuff = new int [ 2 * n ] ; for ( int i = 0 ; i < n ; i ++ ) circBuff [ i ] = arr [ i ] ; for ( int i = n ; i < 2 * n ; i ++ ) circBuff [ i ] = arr [ i - n ] ; int res = int . MinValue ; for ( int i = 0 ; i < n ; i ++ ) res = Math . Max ( computeLIS ( circBuff , i , i + n , n ) , res ) ; return res ; } public static void Main ( ) { int [ ] arr = { 1 , 4 , 6 , 2 , 3 } ; Console . Write ( " Length ▁ of ▁ LICS ▁ is ▁ " + LICS ( arr , arr . Length ) ) ; } }
Counts paths from a point to reach Origin | C # program for above approach ; Function to find binomial Coefficient ; Constructing Pascal 's Triangle ; Driver code
using System ; class GFG { static int binomialCoeff ( int n , int k ) { int [ ] C = new int [ k + 1 ] ; C [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = Math . Min ( i , k ) ; j > 0 ; j -- ) C [ j ] = C [ j ] + C [ j - 1 ] ; } return C [ k ] ; } static void Main ( ) { int n = 3 , m = 2 ; Console . WriteLine ( " Number ▁ of ▁ Paths : ▁ " + binomialCoeff ( n + m , n ) ) ; } }
Longest Common Increasing Subsequence ( LCS + LIS ) | A C # Program to find length of the Longest Common Increasing Subsequence ( LCIS ) ; Returns the length and the LCIS of two arrays arr1 [ 0. . n - 1 ] and arr2 [ 0. . m - 1 ] ; table [ j ] is going to store length of LCIS ending with arr2 [ j ] . We initialize it as 0 , ; Traverse all elements of arr1 [ ] ; Initialize current length of LCIS ; For each element of arr1 [ ] , trvarse all elements of arr2 [ ] . ; If both the array have same elements . Note that we don 't  break the loop here. ; Now seek for previous smaller common element for current element of arr1 ; The maximum value in table [ ] is out result ; Driver program to test above function
using System ; class GFG { static int LCIS ( int [ ] arr1 , int n , int [ ] arr2 , int m ) { int [ ] table = new int [ m ] ; for ( int j = 0 ; j < m ; j ++ ) table [ j ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int current = 0 ; for ( int j = 0 ; j < m ; j ++ ) { if ( arr1 [ i ] == arr2 [ j ] ) if ( current + 1 > table [ j ] ) table [ j ] = current + 1 ; if ( arr1 [ i ] > arr2 [ j ] ) if ( table [ j ] > current ) current = table [ j ] ; } } int result = 0 ; for ( int i = 0 ; i < m ; i ++ ) if ( table [ i ] > result ) result = table [ i ] ; return result ; } public static void Main ( ) { int [ ] arr1 = { 3 , 4 , 9 , 1 } ; int [ ] arr2 = { 5 , 3 , 8 , 9 , 10 , 2 , 1 } ; int n = arr1 . Length ; int m = arr2 . Length ; Console . Write ( " Length ▁ of ▁ LCIS ▁ is ▁ " + LCIS ( arr1 , n , arr2 , m ) ) ; } }
Length of longest common prefix possible by rearranging strings in a given array | C # program to implement the above approach ; Function to get the length of the longest common prefix by rearranging the Strings ; freq [ i , j ] : stores the frequency of a character ( = j ) in a String arr [ i ] ; Traverse the given array ; Stores length of current String ; Traverse current String of the given array ; Update the value of freq [ i , arr [ i , j ] ] ; Stores the length of longest common prefix ; Count the minimum frequency of each character in in all the Strings of [ ] arr ; Stores minimum value in each row of [ , ] freq ; Calculate minimum frequency of current character in all the Strings . ; Update minRowVal ; Update maxLen ; Driver Code
using System ; class GFG { static int longComPre ( String [ ] arr , int N ) { int [ , ] freq = new int [ N , 256 ] ; for ( int i = 0 ; i < N ; i ++ ) { int M = arr [ i ] . Length ; for ( int j = 0 ; j < M ; j ++ ) { freq [ i , arr [ i ] [ j ] ] ++ ; } } int maxLen = 0 ; for ( int j = 0 ; j < 256 ; j ++ ) { int minRowVal = int . MaxValue ; for ( int i = 0 ; i < N ; i ++ ) { minRowVal = Math . Min ( minRowVal , freq [ i , j ] ) ; } maxLen += minRowVal ; } return maxLen ; } public static void Main ( String [ ] args ) { String [ ] arr = { " aabdc " , " abcd " , " aacd " } ; int N = 3 ; Console . Write ( longComPre ( arr , N ) ) ; } }
Remove characters from a String that appears exactly K times | C # program to remove characters from a String that appears exactly K times ; Function to reduce the String by removing the characters which appears exactly k times ; Hash table initialised to 0 ; Increment the frequency of the character ; To store answer ; Next index in reduced string ; Append the characters which appears exactly k times ; Driver code ; Function call
using System ; class GFG { static int MAX_CHAR = 26 ; static String removeChars ( char [ ] arr , int k ) { int [ ] hash = new int [ MAX_CHAR ] ; int n = arr . Length ; for ( int i = 0 ; i < n ; ++ i ) hash [ arr [ i ] - ' a ' ] ++ ; String ans = " " ; for ( int i = 0 ; i < n ; ++ i ) { if ( hash [ arr [ i ] - ' a ' ] != k ) { ans += arr [ i ] ; } } return ans ; } public static void Main ( String [ ] args ) { char [ ] str = " geeksforgeeks " . ToCharArray ( ) ; int k = 2 ; Console . Write ( removeChars ( str , k ) ) ; } }
Contiguous subsegments of a string having distinct subsequent characters | C # implementation of the approach ; Function that prints the segments ; New array for every iteration ; Check if the character is in the array ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void sub_segments ( String str , int n ) { int l = str . Length ; for ( int x = 0 ; x < l ; x += n ) { String newlist = str . Substring ( x , n ) ; List < char > arr = new List < char > ( ) ; foreach ( char y in newlist . ToCharArray ( ) ) { if ( ! arr . Contains ( y ) ) arr . Add ( y ) ; } foreach ( char y in arr ) Console . Write ( y ) ; Console . WriteLine ( ) ; } } public static void Main ( String [ ] args ) { String str = " geeksforgeeksgfg " ; int n = 4 ; sub_segments ( str , n ) ; } }
Program to find the Encrypted word | C # program to implement the above approach ; Static function declared to find the encrypted string ; Character array to store the encrypted string ; after ' z ' , it should go to a . ; storing the character array in the string . ; Driver code
using System ; class GFG { public static void findWord ( String c , int n ) { int co = 0 , i ; char [ ] s = new char [ n ] ; for ( i = 0 ; i < n ; i ++ ) { if ( i < n / 2 ) co ++ ; else co = n - i ; if ( ( c [ i ] + co ) <= 122 ) s [ i ] = ( char ) ( ( int ) c [ i ] + co ) ; else s [ i ] = ( char ) ( ( int ) c [ i ] + co - 26 ) ; } String str = String . Join ( " " , s ) ; Console . WriteLine ( str ) ; } public static void Main ( String [ ] args ) { String s = " abcd " ; findWord ( s , s . Length ) ; } }
Check if two strings are same ignoring their cases | Function to compare two strings ignoring their cases ; length of first string ; length of second string ; if length is not same simply return false since both string can not be same if length is not equal ; loop to match one by one all characters of both string ; if current characters of both string are same , increase value of i to compare next character ; if any character of first string is some special character or numeric character and not same as corresponding character of second string then return false ; do the same for second string ; this block of code will be executed if characters of both strings are of different cases ; compare characters by ASCII value ; if characters matched , increase the value of i to compare next char ; if all characters of the first string are matched with corresponding characters of the second string , then return true ; Function to print the same or not same if strings are equal or not equal ; Driver Code
using System ; class GFG { static bool equalIgnoreCase ( string str1 , string str2 ) { int i = 0 ; int len1 = str1 . Length ; int len2 = str2 . Length ; if ( len1 != len2 ) return false ; while ( i < len1 ) { if ( str1 [ i ] == str2 [ i ] ) { i ++ ; } else if ( ! ( ( str1 [ i ] >= ' a ' && str1 [ i ] <= ' z ' ) || ( str1 [ i ] >= ' A ' && str1 [ i ] <= ' Z ' ) ) ) { return false ; } else if ( ! ( ( str2 [ i ] >= ' a ' && str2 [ i ] <= ' z ' ) || ( str2 [ i ] >= ' A ' && str2 [ i ] <= ' Z ' ) ) ) { return false ; } else { if ( str1 [ i ] >= ' a ' && str1 [ i ] <= ' z ' ) { if ( str1 [ i ] - 32 != str2 [ i ] ) return false ; } else if ( str1 [ i ] >= ' A ' && str1 [ i ] <= ' Z ' ) { if ( str1 [ i ] + 32 != str2 [ i ] ) return false ; } i ++ ; return true ; static void equalIgnoreCaseUtil ( string str1 , string str2 ) { bool res = equalIgnoreCase ( str1 , str2 ) ; if ( res == true ) Console . WriteLine ( " Same " ) ; else Console . WriteLine ( " Not ▁ Same " ) ; } public static void Main ( ) { string str1 , str2 ; str1 = " Geeks " ; str2 = " geeks " ; equalIgnoreCaseUtil ( str1 , str2 ) ; str1 = " Geek " ; str2 = " geeksforgeeks " ; equalIgnoreCaseUtil ( str1 , str2 ) ; } }
Maximize the value of A by replacing some of its digits with digits of B | C # implementation of the approach ; Function to return the maximized value of A ; Sort digits in ascending order ; j points to largest digit in B ; If all the digits of b have been used ; Current digit has been used ; Return the maximized value ; Driver code
using System ; class GFG { static String maxValue ( char [ ] a , char [ ] b ) { Array . Sort ( b ) ; int n = a . Length ; int m = b . Length ; int j = m - 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( j < 0 ) break ; if ( b [ j ] > a [ i ] ) { a [ i ] = b [ j ] ; j -- ; } } return String . Join ( " " , a ) ; } public static void Main ( String [ ] args ) { String a = "1234" ; String b = "4321" ; Console . Write ( maxValue ( a . ToCharArray ( ) , b . ToCharArray ( ) ) ) ; } }
Count numbers in range such that digits in it and it 's product with q are unequal | C # program for above approach ; Function to check if all of the digits in a number and it 's product with q  are unequal or not ; convert first number into string ; Insert elements from 1 st number to hash ; Calculate corresponding product ; Convert the product to string ; Using the hash check if any digit of product matches with the digits of input number ; If yes , return false ; Else , return true ; Function to count numbers in the range [ l , r ] such that all of the digits of the number and it 's product with q are unequal ; check for every number between l and r ; Driver Code ; Function call
using System ; class GfG { static bool checkIfUnequal ( int n , int q ) { string s1 = n . ToString ( ) ; int [ ] a = new int [ 26 ] ; for ( int i = 0 ; i < s1 . Length ; i ++ ) a [ s1 [ i ] - '0' ] ++ ; int prod = n * q ; string s2 = prod . ToString ( ) ; for ( int i = 0 ; i < s2 . Length ; i ++ ) { if ( a [ s2 [ i ] - '0' ] ) return false ; } return true ; } static int countInRange ( int l , int r , int q ) { int count = 0 ; for ( int i = l ; i <= r ; i ++ ) { if ( checkIfUnequal ( i , q ) ) count ++ ; } return count ; } public static void Main ( ) { int l = 10 , r = 12 , q = 2 ; Console . WriteLine ( countInRange ( l , r , q ) ) ; } }
Check if it is possible to rearrange a binary string with alternate 0 s and 1 s | C # program to check if we can rearrange a string such that it has alternate 0 s and 1 s . ; function to check the binary string ; length of string ; count zero 's ; count one 's ; if length is even ; if length is odd ; Driver code
using System ; class GfG { public static bool is_possible ( String s ) { int l = s . Length ; int one = 0 , zero = 0 ; for ( int i = 0 ; i < l ; i ++ ) { if ( s [ i ] == '0' ) zero ++ ; else one ++ ; } if ( l % 2 == 0 ) return ( one == zero ) ; else return ( Math . Abs ( one - zero ) == 1 ) ; } public static void Main ( String [ ] args ) { String s = "100110" ; if ( is_possible ( s ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Frequency Measuring Techniques for Competitive Programming | C # program to count frequencies of array items ; Create an array to store counts . The size of array is limit + 1 and all values are initially 0 ; Traverse through string characters and count frequencies ; Driver Code
using System ; class GFG { static int limit = 25 ; static void countFreq ( String str ) { int [ ] count = new int [ limit + 1 ] ; for ( int i = 0 ; i < str . Length ; i ++ ) count [ str [ i ] - ' A ' ] ++ ; for ( int i = 0 ; i <= limit ; i ++ ) if ( count [ i ] > 0 ) Console . WriteLine ( ( char ) ( i + ' A ' ) + " ▁ " + count [ i ] ) ; } public static void Main ( String [ ] args ) { String str = " GEEKSFORGEEKS " ; countFreq ( str ) ; } }
gOOGLE cASE of a given sentence | C # program to convert given sentence to camel case . ; 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
using System ; class GFG { static String convert ( String s ) { int n = s . Length ; String s1 = " " ; s1 = s1 + Char . ToLower ( s [ 0 ] ) ; for ( int i = 1 ; i < n ; i ++ ) { if ( s [ i ] == ' ▁ ' && i < n ) { s1 = s1 + " ▁ " + Char . ToLower ( s [ i + 1 ] ) ; i ++ ; } else s1 = s1 + Char . ToUpper ( s [ i ] ) ; } return s1 ; } public static void Main ( ) { String str = " I ▁ get ▁ intern ▁ at ▁ geeksforgeeks " ; Console . Write ( convert ( str ) ) ; } }
Transform the string | C # code to transform 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 character ; Function to transform string ; Driver function ; Calling function
using System ; class Gfg { public static String change_case ( string a ) { string temp = " " ; int l = a . Length ; for ( int i = 0 ; i < l ; i ++ ) { char ch = a [ i ] ; if ( ch >= ' a ' && ch <= ' z ' ) ch = ( char ) ( 65 + ( int ) ( ch - ' a ' ) ) ; else if ( ch >= ' A ' && ch <= ' Z ' ) ch = ( char ) ( 97 + ( int ) ( ch - ' A ' ) ) ; temp += ch ; } return temp ; } public static String delete_vowels ( String a ) { String temp = " " ; int l = a . Length ; for ( int i = 0 ; i < l ; i ++ ) { char ch = a [ i ] ; if ( ch != ' a ' && ch != ' e ' && ch != ' i ' && ch != ' o ' && ch != ' u ' && ch != ' A ' && ch != ' E ' && ch != ' O ' && ch != ' U ' && ch != ' I ' ) temp += ch ; } return temp ; } public static String insert_hash ( String a ) { String temp = " " ; int l = a . Length ; char hash = ' # ' ; for ( int i = 0 ; i < l ; i ++ ) { char ch = a [ i ] ; if ( ( ch >= ' a ' && ch <= ' z ' ) || ( ch >= ' A ' && ch <= ' Z ' ) ) temp = temp + hash + ch ; else temp = temp + ch ; } return temp ; } public static void transformString ( string a ) { string b = delete_vowels ( a ) ; string c = change_case ( b ) ; string d = insert_hash ( c ) ; Console . WriteLine ( d ) ; } public static void Main ( ) { string a = " SunshinE ! ! " ; transformString ( a ) ; } }
Tcefrep Numbers | C # program for above approach ; Iterative function to reverse digits of num ; Function to calculate sum of all proper divisors num -- > given natural number ; Final result of summation of divisors ; find all divisors which divides ' num ' ; if ' i ' is divisor of ' num ' ; if both divisors are same then add it only once else add both ; Add 1 to the result as 1 is also a divisor ; Driver Code ; Given Number N ; Function Call
using System ; class GFG { static int reverse ( int num ) { int rev_num = 0 ; while ( num > 0 ) { rev_num = rev_num * 10 + num % 10 ; num = num / 10 ; } return rev_num ; } static int properDivSum ( int num ) { int result = 0 ; for ( int i = 2 ; i <= Math . Sqrt ( num ) ; i ++ ) { if ( num % i == 0 ) { if ( i == ( num / i ) ) result += i ; else result += ( i + num / i ) ; } } return ( result + 1 ) ; } static bool isTcefrep ( int n ) { return properDivSum ( n ) == reverse ( n ) ; } public static void Main ( ) { int N = 6 ; if ( isTcefrep ( N ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Program to find the N | C # program to find n - th number containing only 3 and 5. ; If n is odd , append 3 and move to parent ; If n is even , append 5 and move to parent ; Reverse res and return . ; Driver code
using System ; class GFG { if ( ( n & 1 ) == 1 ) { res = res + " 3 " ; n = ( n - 1 ) / 2 ; } else { res = res + " 5 " ; n = ( n - 2 ) / 2 ; } } string sb = Reverse ( res ) ; return sb ; } static void Main ( ) { int n = 5 ; Console . WriteLine ( findNthNo ( n ) ) ; } }
Nth non | C # program to find n - th non - square number . ; function to find the nth Non - Square Number ; conversion from int to long double is necessary in order to preserve decimal places after square root . ; calculating the result ; Driver code ; initializing the term number ; Print the result
using System ; class GFG { static int findNthNonSquare ( int n ) { double x = ( double ) n ; double ans = x + Math . Floor ( 0.5 + Math . Sqrt ( x ) ) ; return ( int ) ans ; } public static void Main ( ) { int n = 16 ; Console . Write ( " The ▁ " + n + " th ▁ Non - Square ▁ " + " number ▁ is ▁ " ) ; Console . Write ( findNthNonSquare ( n ) ) ; } }