codeparrot/xlcost-text-to-code huggingface dataset:
Difference between Sum of Cubes and Sum of First N Natural Numbers | C # program to find the difference between the sum of the cubes of the first N natural numbers and the sum of the first N natural number ; Sum of first n natural numbers ; Find the required difference ; Driver Code
using System ; class GFG { static int difference ( int n ) { int S , res ; S = ( n * ( n + 1 ) ) / 2 ; res = S * ( S - 1 ) ; return res ; } static public void Main ( ) { int n = 5 ; Console . Write ( difference ( n ) ) ; } }
Check if the sum of digits of number is divisible by all of its digits | C # implementation of the approach ; Function that returns true if all the digits of n divide the sum of the digits of n ; Store a copy of the original number ; Find the sum of the digits of n ; Restore the original value ; Check if all the digits divide the calculated sum ; If current digit doesn 't  divide the sum ; Driver code
using System ; class GFG { static bool isDivisible ( long n ) { long temp = n ; int sum = 0 ; while ( n != 0 ) { int digit = ( int ) n % 10 ; sum += digit ; n /= 10 ; } n = temp ; while ( n != 0 ) { int digit = ( int ) n % 10 ; if ( sum % digit != 0 ) return false ; n /= 10 ; } return true ; } static public void Main ( ) { long n = 123 ; if ( isDivisible ( n ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Program for Mobius Function | Set 2 | C # implementation of the approach ; Function to calculate least prime factor of each number ; If it is a prime number ; For all multiples which are not visited yet . ; Function to find the value of Mobius function for all the numbers from 1 to n ; To store the values of Mobius function ; If number is one ; If number has a squared prime factor ; Multiply - 1 with the previous number ; Driver code ; Function to find least prime factor ; Function to find mobius function
using System ; class GFG { static int N = 100005 ; static int [ ] lpf = new int [ N ] ; static void least_prime_factor ( ) { for ( int i = 2 ; i < N ; i ++ ) if ( lpf [ i ] % 2 != 1 ) for ( int j = i ; j < N ; j += i ) if ( lpf [ j ] % 2 != 0 ) lpf [ j ] = i ; } static void Mobius ( int n ) { int [ ] mobius = new int [ N ] ; for ( int i = 1 ; i < N ; i ++ ) { if ( i == 1 ) mobius [ i ] = 1 ; else { if ( lpf [ i / lpf [ i ] ] == lpf [ i ] ) mobius [ i ] = 0 ; else mobius [ i ] = - 1 * mobius [ i / lpf [ i ] ] ; } } for ( int i = 1 ; i <= n ; i ++ ) Console . Write ( mobius [ i ] + " ▁ " ) ; } static public void Main ( ) { int n = 5 ; Array . Fill ( lpf , - 1 ) ; least_prime_factor ( ) ; Mobius ( n ) ; } }
Make the list non | C # implementation of the approach ; Function to return the minimum element from the range [ prev , MAX ] such that it differs in at most 1 digit with cur ; To start with the value we have achieved in the last step ; Store the value with which the current will be compared ; Current value ; There are at most 4 digits ; If the current digit differs in both the numbers ; Eliminate last digits in both the numbers ; If the number of different digits is at most 1 ; If we can 't find any number for which  the number of change is less than or  equal to 1 then return -1 ; Function to get the non - decreasing list ; Creating a vector for the updated list ; Let 's assume that it is possible to  make the list non-decreasing ; Element of the original array ; Can 't make the list non-decreasing ; If possible then print the list ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int DIGITS = 4 , MIN = 1000 , MAX = 9999 ; static int getBest ( int prev , int cur ) { int maximum = Math . Max ( MIN , prev ) ; for ( int i = maximum ; i <= MAX ; i ++ ) { int cnt = 0 ; int a = i ; int b = cur ; for ( int k = 0 ; k < DIGITS ; k ++ ) { if ( a % 10 != b % 10 ) cnt += 1 ; a /= 10 ; b /= 10 ; } if ( cnt <= 1 ) return i ; } return - 1 ; } static void getList ( int [ ] arr , int n ) { List < int > myList = new List < int > ( ) ; int i , cur ; bool possible = true ; myList . Add ( 0 ) ; for ( i = 0 ; i < n ; i ++ ) { cur = arr [ i ] ; myList . Add ( getBest ( myList [ myList . Count - 1 ] , cur ) ) ; if ( myList [ myList . Count - 1 ] == - 1 ) { possible = false ; break ; } } if ( possible ) { for ( i = 1 ; i < myList . Count ; i ++ ) Console . Write ( myList [ i ] + " ▁ " ) ; } else Console . Write ( " - 1" ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1095 , 1094 , 1095 } ; int n = arr . Length ; getList ( arr , n ) ; } }
Maximum items that can be bought with the given type of coins | C # implementation of the approach ; Function to find maximum fruits Can buy from given values of x , y , z . ; Items of type 1 that can be bought ; Update the coins ; Items of type 2 that can be bought ; Update the coins ; Items of type 3 that can be bought ; Update the coins ; Items of type 4 that can be bought To buy a type 4 item , a coin of each type is required ; Total items that can be bought ; Driver code
using System ; class GFG { static int COST = 3 ; static int maxItems ( int x , int y , int z ) { int type1 = x / COST ; x %= COST ; int type2 = y / COST ; y %= COST ; int type3 = z / COST ; z %= COST ; int type4 = Math . Min ( x , Math . Min ( y , z ) ) ; int maxItems = type1 + type2 + type3 + type4 ; return maxItems ; } static public void Main ( ) { int x = 4 , y = 5 , z = 6 ; Console . Write ( maxItems ( x , y , z ) ) ; } }
Count occurrences of a prime number in the prime factorization of every element from the given range | C # implementation of the approach ; Function to return the highest power of p that divides n ; Function to return the count of times p appears in the prime factors of the elements from the range [ l , r ] ; To store the required count ; For every element of the range ; Add the highest power of p that divides i ; Driver code
using System ; class GFG { static int countFactors ( int n , int p ) { int pwr = 0 ; while ( n > 0 && n % p == 0 ) { n /= p ; pwr ++ ; } return pwr ; } static int getCount ( int l , int r , int p ) { int cnt = 0 ; for ( int i = l ; i <= r ; i ++ ) { cnt += countFactors ( i , p ) ; } return cnt ; } public static void Main ( String [ ] args ) { int l = 2 , r = 8 , p = 2 ; Console . WriteLine ( getCount ( l , r , p ) ) ; } }
Count occurrences of a prime number in the prime factorization of every element from the given range | C # implementation of the approach ; Function to return the count of times p appears in the prime factors of the elements from the range [ l , r ] ; To store the required count ; Number of values in the range [ 0 , r ] that are divisible by val ; Number of values in the range [ 0 , l - 1 ] that are divisible by val ; Increment the power of the val ; ( a - b ) is the count of numbers in the range [ l , r ] that are divisible by val ; No values that are divisible by val thus exiting from the loop ; Driver code
using System ; class GFG { static int getCount ( int l , int r , int p ) { int cnt = 0 ; int val = p ; while ( true ) { int a = r / val ; int b = ( l - 1 ) / val ; val *= p ; if ( ( a - b ) > 0 ) { cnt += ( a - b ) ; } else break ; } return cnt ; } public static void Main ( String [ ] args ) { int l = 2 , r = 8 , p = 2 ; Console . WriteLine ( getCount ( l , r , p ) ) ; } }
Check if the number is valid when flipped upside down | C # implementation of the approach ; Function that returns true if str is Topsy Turvy ; For every character of the string ; If the current digit cannot form a valid digit when turned upside - down ; Driver code
using System ; class GFG { static bool topsyTurvy ( char [ ] str ) { for ( int i = 0 ; i < str . Length ; i ++ ) { if ( str [ i ] == '2' str [ i ] == '4' str [ i ] == '5' str [ i ] == '6' str [ i ] == '7' str [ i ] == '9' ) { return false ; } } return true ; } public static void Main ( String [ ] args ) { String str = "1234" ; if ( topsyTurvy ( str . ToCharArray ( ) ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Find the count of subsequences where each element is divisible by K | C # implementation of the approach ; Function to return the count of all valid subsequences ; To store the count of elements which are divisible by k ; If current element is divisible by k then increment the count ; Total ( 2 ^ n - 1 ) non - empty subsequences are possible with n element ; Driver code
using System ; class GFG { static int countSubSeq ( int [ ] arr , int n , int k ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % k == 0 ) { count ++ ; } } return ( int ) ( Math . Pow ( 2 , count ) - 1 ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 6 } ; int n = arr . Length ; int k = 3 ; Console . WriteLine ( countSubSeq ( arr , n , k ) ) ; } }
Count of numbers below N whose sum of prime divisors is K | C # implementation of the approach ; Function to return the count of numbers below N whose sum of prime factors is K ; To store the sum of prime factors for all the numbers ; If i is prime ; Add i to all the numbers which are divisible by i ; To store the count of required numbers ; Return the required count ; Driver code
using System ; class GFG { static int MAX = 1000001 ; static int countNum ( int N , int K ) { int [ ] sumPF = new int [ MAX ] ; for ( int i = 2 ; i < N ; i ++ ) { if ( sumPF [ i ] == 0 ) { for ( int j = i ; j < N ; j += i ) { sumPF [ j ] += i ; } } } int count = 0 ; for ( int i = 2 ; i < N ; i ++ ) { if ( sumPF [ i ] == K ) count ++ ; } return count ; } public static void Main ( String [ ] args ) { int N = 20 , K = 7 ; Console . WriteLine ( countNum ( N , K ) ) ; } }
Queries for the smallest and the largest prime number of given digit | C # implementation of the approach ; 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 greater than or equal to the square of it numbers which are multiple of p and are less than p ^ 2 are already been marked . ; Function to return the smallest prime number with d digits ; check if prime ; Function to return the largest prime number with d digits ; check if prime ; Driver code ; Perform queries
using System ; class GFG { static int MAX = 100000 ; static bool [ ] prime = new bool [ MAX + 1 ] ; static void SieveOfEratosthenes ( ) { for ( int i = 0 ; i < MAX + 1 ; i ++ ) { prime [ i ] = true ; } for ( int p = 2 ; p * p <= MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * p ; i <= MAX ; i += p ) prime [ i ] = false ; } } } static int smallestPrime ( int d ) { int l = ( int ) Math . Pow ( 10 , d - 1 ) ; int r = ( int ) Math . Pow ( 10 , d ) - 1 ; for ( int i = l ; i <= r ; i ++ ) { if ( prime [ i ] ) { return i ; } } return - 1 ; } static int largestPrime ( int d ) { int l = ( int ) Math . Pow ( 10 , d - 1 ) ; int r = ( int ) Math . Pow ( 10 , d ) - 1 ; for ( int i = r ; i >= l ; i -- ) { if ( prime [ i ] ) { return i ; } } return - 1 ; } public static void Main ( String [ ] args ) { SieveOfEratosthenes ( ) ; int [ ] queries = { 2 , 5 } ; int q = queries . Length ; for ( int i = 0 ; i < q ; i ++ ) { Console . WriteLine ( smallestPrime ( queries [ i ] ) + " ▁ " + largestPrime ( queries [ i ] ) ) ; } } }
Find a Square Matrix such that sum of elements in every row and column is K | C # implementation of the approach ; Function to print the required matrix ; Print k for the left diagonal elements ; Print 0 for the rest ; Driver code
using System ; class GFG { static void printMatrix ( int n , int k ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( i == j ) Console . Write ( k + " ▁ " ) ; else Console . Write ( "0 ▁ " ) ; } Console . Write ( " STRNEWLINE " ) ; } } public static void Main ( String [ ] args ) { int n = 3 , k = 7 ; printMatrix ( n , k ) ; } }
Divide first N natural numbers into 3 equal sum subsets | C # implementation of the approach ; Function that returns true if the subsets are possible ; If n <= 3 then it is not possible to divide the elements in three subsets satisfying the given conditions ; Sum of all the elements in the range [ 1 , n ] ; If the sum is divisible by 3 then it is possible ; Driver code
using System ; class GFG { public static bool possible ( int n ) { if ( n > 3 ) { int sum = ( n * ( n + 1 ) ) / 2 ; if ( sum % 3 == 0 ) { return true ; } } return false ; } static public void Main ( ) { int n = 5 ; if ( possible ( n ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Find the Nth element of the modified Fibonacci series | C # implementation of the approach ; Function to return the Nth number of the modified Fibonacci series where A and B are the first two terms ; To store the current element which is the sum of previous two elements of the series ; This loop will terminate when the Nth element is found ; Return the Nth element ; Driver code
using System ; class GFG { static int findNthNumber ( int A , int B , int N ) { int sum = 0 ; for ( int i = 2 ; i < N ; i ++ ) { sum = A + B ; A = B ; B = sum ; } return sum ; } public static void Main ( ) { int A = 5 , B = 7 , N = 10 ; Console . WriteLine ( findNthNumber ( A , B , N ) ) ; } }
Check if an array is increasing or decreasing | C # implementation of the approach ; Function to check the type of the array ; If the first two and the last two elements of the array are in increasing order ; If the first two and the last two elements of the array are in decreasing order ; If the first two elements of the array are in increasing order and the last two elements of the array are in decreasing order ; If the first two elements of the array are in decreasing order and the last two elements of the array are in increasing order ; Driver code
using System ; class GFG { public static void checkType ( int [ ] arr , int n ) { if ( arr [ 0 ] <= arr [ 1 ] && arr [ n - 2 ] <= arr [ n - 1 ] ) Console . Write ( " Increasing " ) ; else if ( arr [ 0 ] >= arr [ 1 ] && arr [ n - 2 ] >= arr [ n - 1 ] ) Console . Write ( " Decreasing " ) ; else if ( arr [ 0 ] <= arr [ 1 ] && arr [ n - 2 ] >= arr [ n - 1 ] ) Console . Write ( " Increasing ▁ then ▁ decreasing " ) ; else Console . Write ( " Decreasing ▁ then ▁ increasing " ) ; } static public void Main ( ) { int [ ] arr = new int [ ] { 1 , 2 , 3 , 4 } ; int n = arr . Length ; checkType ( arr , n ) ; } }
Calculate the IST : Indian Standard Time | C # implementation of the approach ; Function to calculate Indian Standard Time ; Separate integer part ; Separate float part and return ceil value ; Driver code ; Number of hours ( 1 - 24 ) ; Rotations in degrees
using System ; class GFG { public static void cal_IST ( int h , double r ) { double IST = ( h * r * 1.0 ) / 360 ; int int_IST = ( int ) IST ; int float_IST = ( int ) Math . Floor ( ( double ) ( IST - int_IST ) * 60 ) ; Console . WriteLine ( int_IST + " : " + float_IST ) ; } public static void Main ( String [ ] args ) { int h = 20 ; double r = 150 ; cal_IST ( h , r ) ; } }
Check if it is possible to perform the given Grid Division | C # implementation of the approach ; Function that returns true if it is possible to divide the grid satisfying the given conditions ; To store the sum of all the cells of the given parts ; If the sum is equal to the total number of cells in the given grid ; Driver code
using System ; class GFG { static bool isPossible ( int [ ] arr , int p , int n , int m ) { int sum = 0 ; for ( int i = 0 ; i < p ; i ++ ) sum += arr [ i ] ; if ( sum == ( n * m ) ) return true ; return false ; } public static void Main ( String [ ] args ) { int n = 3 , m = 4 ; int [ ] arr = { 6 , 3 , 2 , 1 } ; int p = arr . Length ; if ( isPossible ( arr , p , n , m ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Minimum steps to make the product of the array equal to 1 | C # implementation of the approach ; Function to return the minimum steps required ; To store the count of 0 s , positive and negative numbers ; To store the ans ; If array element is equal to 0 ; If array element is a negative number ; Extra cost needed to make it - 1 ; If array element is a positive number ; Extra cost needed to make it 1 ; Now the array will have - 1 , 0 and 1 only ; As count of negative is even so we will change all 0 to 1 total cost here will be count of 0 s ; If there are zeroes present in the array ; Change one zero to - 1 and rest of them to 1 Total cost here will be count of '0' ; If there are no zeros in the array ; As no 0 s are available so we have to change one - 1 to 1 which will cost 2 to change - 1 to 1 ; Driver code
using System ; class GFG { static int MinStep ( int [ ] a , int n ) { int positive = 0 , negative = 0 , zero = 0 ; int step = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == 0 ) { zero ++ ; } else if ( a [ i ] < 0 ) { negative ++ ; step = step + ( - 1 - a [ i ] ) ; } else { positive ++ ; step = step + ( a [ i ] - 1 ) ; } } if ( negative % 2 == 0 ) { step = step + zero ; } else { if ( zero > 0 ) { step = step + zero ; } else { step = step + 2 ; } } return step ; } static public void Main ( ) { int [ ] a = { 0 , - 2 , - 1 , - 3 , 4 } ; int n = a . Length ; Console . Write ( MinStep ( a , n ) ) ; } }
Find the first N integers such that the sum of their digits is equal to 10 | C # implementation of the approach ; Function to return the sum of digits of n ; Add the last digit to the sum ; Remove last digit ; Return the sum of digits ; Function to print the first n numbers whose sum of digits is 10 ; First number of the series is 19 ; If the sum of digits of the current number is equal to 10 ; Print the number ; Add 9 to the previous number ; Driver code
using System ; class GFG { static int sum ( int n ) { int sum = 0 ; while ( n > 0 ) { sum = sum + n % 10 ; n = n / 10 ; } return sum ; } static void firstN ( int n ) { int num = 19 , cnt = 1 ; while ( cnt != n ) { if ( sum ( num ) == 10 ) { Console . Write ( num + " ▁ " ) ; cnt ++ ; } num += 9 ; } } public static void Main ( String [ ] args ) { int n = 10 ; firstN ( n ) ; } }
Sum of last digit of all integers from 1 to N divisible by M | C # implementation of the approach ; Function to return the required sum ; Number of element between 1 to n divisible by m ; Array to store the last digit of elements in a cycle ; Storing and adding last digit of cycle ; Number of elements present in last cycle ; Sum of k / 10 cycle ; Adding value of digits of last cycle to the answer ; Driver Code ; input n and m
using System ; class GFG { static long sumOfLastDig ( long n , long m ) { long sum = 0 , k ; k = n / m ; long [ ] arr = new long [ 10 ] ; for ( int i = 0 ; i < 10 ; i ++ ) { arr [ i ] = m * ( i + 1 ) % 10 ; sum += arr [ i ] ; } long rem = k % 10 ; long ans = ( k / 10 ) * sum ; for ( int i = 0 ; i < rem ; i ++ ) { ans += arr [ i ] ; } return ans ; } static public void Main ( ) { long n = 100 , m = 3 ; Console . Write ( sumOfLastDig ( n , m ) ) ; } }
Number of Subsequences with Even and Odd Sum | Set 2 | C # program to find number of Subsequences with Even and Odd Sum ; Function to find number of Subsequences with Even and Odd Sum ; Counting number of odds ; Even count ; Total Subsequences is ( 2 ^ n - 1 ) For NumberOfEvenSubsequences subtract NumberOfOddSubsequences from total ; Driver code ; Calling the function
using System ; class GFG { public class pair { public int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static pair countSum ( int [ ] arr , int n ) { int NumberOfOdds = 0 , NumberOfEvens = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( arr [ i ] % 2 == 1 ) NumberOfOdds ++ ; NumberOfEvens = n - NumberOfOdds ; int NumberOfOddSubsequences = ( 1 << NumberOfEvens ) * ( 1 << ( NumberOfOdds - 1 ) ) ; int NumberOfEvenSubsequences = ( 1 << n ) - 1 - NumberOfOddSubsequences ; return new pair ( NumberOfEvenSubsequences , NumberOfOddSubsequences ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 2 , 3 } ; int n = arr . Length ; pair ans = countSum ( arr , n ) ; Console . Write ( " EvenSum ▁ = ▁ " + ans . first ) ; Console . Write ( " ▁ OddSum ▁ = ▁ " + ans . second ) ; } }
Program to find the next prime number | C # implementation of the approach ; Function that returns true if n is prime else returns false ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Function to return the smallest prime number greater than N ; Base case ; Loop continuously until isPrime returns true for a number greater than n ; Driver code
using System ; class GFG { static bool 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 int nextPrime ( int N ) { if ( N <= 1 ) return 2 ; int prime = N ; bool found = false ; while ( ! found ) { prime ++ ; if ( isPrime ( prime ) ) found = true ; } return prime ; } public static void Main ( String [ ] args ) { int N = 3 ; Console . WriteLine ( nextPrime ( N ) ) ; } }
Check if a number is Flavius Number | C # implementation of the above approach ; Return the number is Flavious Number or not ; index i starts from 2 because at 1 st iteration every 2 nd element was remove and keep going for k - th iteration ; removing the elements which are already removed at kth iteration ; Driver Code
using System ; class GFG { static bool Survives ( int n ) { for ( int i = 2 ; ; i ++ ) { if ( i > n ) return true ; if ( n % i == 0 ) return false ; n -= n / i ; } } public static void Main ( String [ ] args ) { int n = 17 ; if ( Survives ( n ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Nth XOR Fibonacci number | C # implementation of the above approach ; Function to return the nth XOR Fibonacci number ; Driver code
using System ; class GFG { static int nthXorFib ( int n , int a , int b ) { if ( n == 0 ) return a ; if ( n == 1 ) return b ; if ( n == 2 ) return ( a ^ b ) ; return nthXorFib ( n % 3 , a , b ) ; } public static void Main ( String [ ] args ) { int a = 1 , b = 2 , n = 10 ; Console . WriteLine ( nthXorFib ( n , a , b ) ) ; } }
Sand Timer Flip Counting Problem | C # implementation of the approach ; Recursive function to return the gcd of a and b ; Everything divides 0 ; Function to print the number of flips for both the sand timers ; Driver code
using System ; class GFG { static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } static void flip ( int a , int b ) { int lcm = ( a * b ) / gcd ( a , b ) ; a = lcm / a ; b = lcm / b ; Console . WriteLine ( ( a - 1 ) + " ▁ " + ( b - 1 ) ) ; } public static void Main ( ) { int a = 10 ; int b = 5 ; flip ( a , b ) ; } }
Sum of N terms in the expansion of Arcsin ( x ) | C # implementation of the approach ; Function to find the arcsin ( x ) ; The power to which ' x ' is raised ; Numerator value ; Denominator value ; Driver code
using System ; class GFG { static void find_Solution ( double x , int n ) { double sum = x , e = 2 , o = 1 , p = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { p += 2 ; sum += ( double ) ( o / e ) * ( double ) ( Math . Pow ( x , p ) / p ) ; o = o * ( o + 2 ) ; e = e * ( e + 2 ) ; } Console . WriteLine ( sum ) ; } public static void Main ( String [ ] args ) { double x = - 0.5 ; if ( Math . Abs ( x ) >= 1 ) { Console . WriteLine ( " Invalid ▁ Input " ) ; } int n = 8 ; find_Solution ( x , n ) ; } }
Minimize the cost of buying the Objects | C # implementation of the approach ; Function that will calculate the price ; Calculate the number of items we can get for free ; Calculate the number of items we will have to pay the price for ; Calculate the price ; Driver code ; Calling function
using System ; class GFG { static int totalPay ( int totalItems , int priceOfOneItem , int N , int M ) { int freeItems = 0 , actual = 0 ; freeItems = totalItems / ( N + M ) ; actual = totalItems - freeItems ; int amount = actual * priceOfOneItem ; return amount ; } public static void Main ( String [ ] args ) { int T = 12 , P = 8 ; int N = 2 , M = 1 ; Console . Write ( " Amount ▁ = ▁ " + totalPay ( T , P , N , M ) ) ; } }