codeparrot/xlcost-text-to-code huggingface dataset:
Program for Volume and Surface area of Frustum of Cone | C # program to calculate Volume and Surface area of frustum of cone ; Function to calculate Volume of frustum of cone ; Function to calculate Curved Surface area of frustum of cone ; Function to calculate Total Surface area of frustum of cone ; Driver function ; Printing value of volume and surface area
using System ; public class demo { static float pi = 3.14159f ; public static float volume ( float r , float R , float h ) { return ( float ) 1 / 3 * pi * h * ( r * r + R * R + r * R ) ; } public static float curved_surface_area ( float r , float R , float l ) { return pi * l * ( R + r ) ; } public static float total_surface_area ( float r , float R , float l , float h ) { return pi * l * ( R + r ) + pi * ( r * r + R * R ) ; } public static void Main ( ) { float small_radius = 3 ; float big_radius = 8 ; float slant_height = 13 ; float height = 12 ; Console . Write ( " Volume ▁ Of ▁ Frustum ▁ of ▁ Cone ▁ : ▁ " ) ; Console . WriteLine ( volume ( small_radius , big_radius , height ) ) ; Console . Write ( " Curved ▁ Surface ▁ Area ▁ Of " + " ▁ Frustum ▁ of ▁ Cone ▁ : ▁ " ) ; Console . WriteLine ( curved_surface_area ( small_radius , big_radius , slant_height ) ) ; Console . Write ( " Total ▁ Surface ▁ Area ▁ Of " + " ▁ Frustum ▁ of ▁ Cone ▁ : ▁ " ) ; Console . WriteLine ( total_surface_area ( small_radius , big_radius , slant_height , height ) ) ; } }
Program to find Perimeter / Circumference of Square and Rectangle | C # program to find Circumference of a square ; Driver Code
using System ; class GFG { static int Circumference ( int a ) { return 4 * a ; } public static void Main ( ) { int a = 5 ; Console . WriteLine ( " Circumference " + " ▁ of ▁ a ▁ square ▁ is ▁ " + Circumference ( a ) ) ; } }
Maximum area of quadrilateral | C # program to find maximum are of a quadrilateral ; Calculating the semi - perimeter of the given quadrilateral ; Applying Brahmagupta 's formula to  get maximum area of quadrilateral ; Driver code
using System ; class GFG { static double maxArea ( double a , double b , double c , double d ) { double semiperimeter = ( a + b + c + d ) / 2 ; return Math . Sqrt ( ( semiperimeter - a ) * ( semiperimeter - b ) * ( semiperimeter - c ) * ( semiperimeter - d ) ) ; } public static void Main ( ) { double a = 1 , b = 2 , c = 1 , d = 2 ; Console . WriteLine ( maxArea ( a , b , c , d ) ) ; } }
Direction of a Point from a Line Segment | C # Program to Determine Direction of Point from line segment ; structure for point in cartesian plane . ; constant integers for directions ; subtracting co - ordinates of point A from B and P , to make A as origin ; Determining cross Product ; return RIGHT if cross product is positive ; return LEFT if cross product is negative ; return ZERO if cross product is zero . ; Driver code ; A . y = 10 ; A ( - 30 , 10 ) ; B . y = - 15 ; B ( 29 , - 15 ) ; P . y = 28 ; P ( 15 , 28 )
using System ; using System . Collections . Generic ; class GFG { public class point { public int x , y ; } ; static int RIGHT = 1 , LEFT = - 1 , ZERO = 0 ; static int directionOfPoint ( point A , point B , point P ) { B . x -= A . x ; B . y -= A . y ; P . x -= A . x ; P . y -= A . y ; int cross_product = B . x * P . y - B . y * P . x ; if ( cross_product > 0 ) return RIGHT ; if ( cross_product < 0 ) return LEFT ; return ZERO ; } public static void Main ( String [ ] args ) { point A = new point ( ) , B = new point ( ) , P = new point ( ) ; A . x = - 30 ; B . x = 29 ; P . x = 15 ; int direction = directionOfPoint ( A , B , P ) ; if ( direction == 1 ) Console . WriteLine ( " Right ▁ Direction " ) ; else if ( direction == - 1 ) Console . WriteLine ( " Left ▁ Direction " ) ; else Console . WriteLine ( " Point ▁ is ▁ on ▁ the ▁ Line " ) ; } }
Find minimum radius such that atleast k point lie inside the circle | C # program to find minimum radius such that atleast k point lie inside the circle ; Return minimum distance required so that aleast k point lie inside the circle . ; Finding distance between of each point from origin ; Sorting the distance ; Driven Program
using System ; class GFG { static int minRadius ( int k , int [ ] x , int [ ] y , int n ) { int [ ] dis = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) dis [ i ] = x [ i ] * x [ i ] + y [ i ] * y [ i ] ; Array . Sort ( dis ) ; return dis [ k - 1 ] ; } public static void Main ( ) { int k = 3 ; int [ ] x = { 1 , - 1 , 1 } ; int [ ] y = { 1 , - 1 , - 1 } ; int n = x . Length ; Console . WriteLine ( minRadius ( k , x , y , n ) ) ; } }
Program for Area And Perimeter Of Rectangle | C # program to find area and perimeter of rectangle ; Utility function ; Driver Function
using System ; class GFG { static int areaRectangle ( int a , int b ) { int area = a * b ; return area ; } static int perimeterRectangle ( int a , int b ) { int perimeter = 2 * ( a + b ) ; return perimeter ; } public static void Main ( ) { int a = 5 ; int b = 6 ; Console . WriteLine ( " Area ▁ = ▁ " + areaRectangle ( a , b ) ) ; Console . WriteLine ( " Perimeter ▁ = ▁ " + perimeterRectangle ( a , b ) ) ; } }
Program for Area Of Square | C # program to find the area of the square ; Driver code
using System ; class GFG { static int areaSquare ( int side ) { int area = side * side ; return area ; } public static void Main ( ) { int side = 4 ; Console . WriteLine ( areaSquare ( side ) ) ; } }
Minimum Perimeter of n blocks | C # Code to find minimum perimeter using n blocks ; if n is a perfect square ; Number of rows ; perimeter of the rectangular grid ; if there are blocks left ; Driver code
using System ; class GFG { public static long minPerimeter ( int n ) { int l = ( int ) Math . Sqrt ( n ) ; int sq = l * l ; if ( sq == n ) return l * 4 ; else { long row = n / l ; long perimeter = 2 * ( l + row ) ; if ( n % l != 0 ) perimeter += 2 ; return perimeter ; } } public static void Main ( ) { int n = 10 ; Console . Write ( minPerimeter ( n ) ) ; } }
Find if it 's possible to rotate the page by an angle or not. | C # program to fill an array with frequencies . ; function to find if it 's possible  to rotate page or not ; Calculating distance b / w points ; If distance is not equal ; If the points are in same line ; Driver method ; Points a , b , and c
using System ; class GFG { static void possibleOrNot ( long a1 , long a2 , long b1 , long b2 , long c1 , long c2 ) { long dis1 = ( long ) Math . Pow ( b1 - a1 , 2 ) + ( long ) Math . Pow ( b2 - a2 , 2 ) ; long dis2 = ( long ) Math . Pow ( c1 - b1 , 2 ) + ( long ) Math . Pow ( c2 - b2 , 2 ) ; if ( dis1 != dis2 ) Console . Write ( " No " ) ; else if ( b1 == ( ( a1 + c1 ) / 2.0 ) && b2 == ( ( a2 + c2 ) / 2.0 ) ) Console . Write ( " No " ) ; else Console . Write ( " Yes " ) ; } public static void Main ( ) { long a1 = 1 , a2 = 0 , b1 = 2 , b2 = 0 , c1 = 3 , c2 = 0 ; possibleOrNot ( a1 , a2 , b1 , b2 , c1 , c2 ) ; } }
Check if two given circles touch or intersect each other | C # program to check if two circles touch each other or not . ; Driver code
using System ; class GFG { static int circle ( int x1 , int y1 , int x2 , int y2 , int r1 , int r2 ) { int distSq = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ; int radSumSq = ( r1 + r2 ) * ( r1 + r2 ) ; if ( distSq == radSumSq ) return 1 ; else if ( distSq > radSumSq ) return - 1 ; else return 0 ; } public static void Main ( ) { int x1 = - 10 , y1 = 8 ; int x2 = 14 , y2 = - 24 ; int r1 = 30 , r2 = 10 ; int t = circle ( x1 , y1 , x2 , y2 , r1 , r2 ) ; if ( t == 1 ) Console . WriteLine ( " Circle ▁ touch " + " ▁ to ▁ each ▁ other . " ) ; else if ( t < 0 ) Console . WriteLine ( " Circle ▁ not ▁ touch " + " ▁ to ▁ each ▁ other . " ) ; else Console . WriteLine ( " Circle ▁ intersect " + " ▁ to ▁ each ▁ other . " ) ; } }
Count of obtuse angles in a circle with ' k ' equidistant points between 2 given points | C # program to count number of obtuse angles for given two points ; There are two arcs connecting a and b . Let us count points on both arcs . ; Both arcs have same number of points ; Points on smaller arc is answer ; Driver Program to test above function
using System ; class GFG { static int countObtuseAngles ( int a , int b , int k ) { int c1 = ( b - a ) - 1 ; int c2 = ( k - b ) + ( a - 1 ) ; if ( c1 == c2 ) return 0 ; return Math . Min ( c1 , c2 ) ; } public static void Main ( ) { int k = 6 , a = 1 , b = 3 ; Console . WriteLine ( countObtuseAngles ( a , b , k ) ) ; } }
Find points at a given distance on a line of given slope | C # program to find the points on a line of slope M at distance L ; Class to represent a co - ordinate point ; Function to print pair of points at distance ' l ' and having a slope ' m ' from the source ; m is the slope of line , and the required Point lies distance l away from the source Point ; Slope is 0 ; If slope is infinite ; Print the first Point ; Print the second Point ; Driver code
using System ; class GFG { public class Point { public float x , y ; public Point ( ) { x = y = 0 ; } public Point ( float a , float b ) { x = a ; y = b ; } } ; static void printPoints ( Point source , float l , int m ) { Point a = new Point ( ) ; Point b = new Point ( ) ; if ( m == 0 ) { a . x = source . x + l ; a . y = source . y ; b . x = source . x - l ; b . y = source . y ; } else if ( Double . IsInfinity ( m ) ) { a . x = source . x ; a . y = source . y + l ; b . x = source . x ; b . y = source . y - l ; } else { float dx = ( float ) ( l / Math . Sqrt ( 1 + ( m * m ) ) ) ; float dy = m * dx ; a . x = source . x + dx ; a . y = source . y + dy ; b . x = source . x - dx ; b . y = source . y - dy ; } Console . WriteLine ( a . x + " , ▁ " + a . y ) ; Console . WriteLine ( b . x + " , ▁ " + b . y ) ; } public static void Main ( String [ ] args ) { Point p = new Point ( 2 , 1 ) , q = new Point ( 1 , 0 ) ; printPoints ( p , ( float ) Math . Sqrt ( 2 ) , 1 ) ; Console . WriteLine ( ) ; printPoints ( q , 5 , 0 ) ; } }
Minimum block jumps to reach destination | C # program to find minimum jumps to reach a given destination from a given source ; To represent point in 2D space ; To represent line of ( ax + by + c ) format ; Returns 1 if evaluation is greater > 0 , else returns - 1 ; Returns minimum jumps to reach dest point from start point ; get sign of evaluation from point co - ordinate and line equation ; if both evaluation are of opposite sign , increase jump by 1 ; Driver code
using System ; class GFG { class point { public int x , y ; public point ( int x , int y ) { this . x = x ; this . y = y ; } } ; class line { public int a , b , c ; line ( ) { } public line ( int a , int b , int c ) { this . a = a ; this . b = b ; this . c = c ; } } ; static int evalPointOnLine ( point p , line curLine ) { int eval = curLine . a * p . x + curLine . b * p . y + curLine . c ; if ( eval > 0 ) return 1 ; return - 1 ; } static int minJumpToReachDestination ( point start , point dest , line [ ] lines , int N ) { int jumps = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int signStart = evalPointOnLine ( start , lines [ i ] ) ; int signDest = evalPointOnLine ( dest , lines [ i ] ) ; if ( signStart * signDest < 0 ) jumps ++ ; } return jumps ; } public static void Main ( String [ ] args ) { point start = new point ( 1 , 1 ) ; point dest = new point ( - 2 , - 1 ) ; line [ ] lines = new line [ 3 ] ; lines [ 0 ] = new line ( 1 , 0 , 0 ) ; lines [ 1 ] = new line ( 0 , 1 , 0 ) ; lines [ 2 ] = new line ( 1 , 1 , - 2 ) ; Console . Write ( minJumpToReachDestination ( start , dest , lines , 3 ) ) ; } }
Minimum distance to travel to cover all intervals | C # program to find minimum distance to travel to cover all intervals ; Structure to store an interval ; Method returns minimum distance to travel to cover all intervals ; Looping over all intervals to get right most start and left most end ; If rightmost start > leftmost end then all intervals are not aligned and it is not possible to cover all of them ; If x is in between rightmoststart and leftmostend then no need to travel any distance ; Choose minimum according to current position x ; Driver code
using System ; class GFG { public class Interval { public int start , end ; public Interval ( int start , int end ) { this . start = start ; this . end = end ; } } ; static int minDistanceToCoverIntervals ( Interval [ ] intervals , int N , int x ) { int rightMostStart = int . MinValue ; int leftMostEnd = int . MaxValue ; for ( int i = 0 ; i < N ; i ++ ) { if ( rightMostStart < intervals [ i ] . start ) rightMostStart = intervals [ i ] . start ; if ( leftMostEnd > intervals [ i ] . end ) leftMostEnd = intervals [ i ] . end ; } int res ; if ( rightMostStart > leftMostEnd ) res = - 1 ; else if ( rightMostStart <= x && x <= leftMostEnd ) res = 0 ; else res = ( x < rightMostStart ) ? ( rightMostStart - x ) : ( x - leftMostEnd ) ; return res ; } public static void Main ( String [ ] args ) { int x = 3 ; Interval [ ] intervals = { new Interval ( 0 , 7 ) , new Interval ( 2 , 14 ) , new Interval ( 4 , 6 ) } ; int N = intervals . Length ; int res = minDistanceToCoverIntervals ( intervals , N , x ) ; if ( res == - 1 ) Console . Write ( " Not ▁ Possible ▁ to ▁ " + " cover ▁ all ▁ intervals STRNEWLINE " ) ; else Console . Write ( res + " STRNEWLINE " ) ; } }
Count of acute , obtuse and right triangles with given sides | C # program to count of acute , obtuse and right triangles in an array ; Find the number of acute , right , obtuse triangle that can be formed from given array . ; Finding the square of each element of array . ; Sort the sides of array and their squares . ; x for acute triangles y for right triangles z for obtuse triangles ; Finding the farthest point p where a ^ 2 + b ^ 2 >= c ^ 2. ; Finding the farthest point q where a + b > c . ; If point p make right triangle . ; All triangle between j and p are acute triangles . So add p - j - 1 in x . ; Increment y by 1. ; All triangle between q and p are acute triangles . So add q - p in z . ; If no right triangle ; All triangle between j and p are acute triangles . So add p - j in x . ; All triangle between q and p are acute triangles . So add q - p in z . ; Driver Code
using System ; class GFG { static void findTriangle ( int [ ] a , int n ) { int [ ] b = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) b [ i ] = a [ i ] * a [ i ] ; Array . Sort ( a ) ; Array . Sort ( b ) ; int x = 0 , y = 0 , z = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int p = i + 1 ; int q = i + 1 ; for ( int j = i + 1 ; j < n ; j ++ ) { while ( p < n - 1 && b [ i ] + b [ j ] >= b [ p + 1 ] ) p ++ ; q = Math . Max ( q , p ) ; while ( q < n - 1 && a [ i ] + a [ j ] > a [ q + 1 ] ) q ++ ; if ( b [ i ] + b [ j ] == b [ p ] ) { x += Math . Max ( p - j - 1 , 0 ) ; y ++ ; z += q - p ; } else { x += Math . Max ( p - j , 0 ) ; z += q - p ; } } } Console . Write ( " Acute ▁ Triangle : ▁ " + x + " STRNEWLINE " ) ; Console . Write ( " Right ▁ Triangle : ▁ " + y + " STRNEWLINE " ) ; Console . Write ( " Obtuse ▁ Triangle : ▁ " + z + " STRNEWLINE " ) ; } public static void Main ( string [ ] args ) { int [ ] arr = { 2 , 3 , 9 , 10 , 12 , 15 } ; int n = arr . Length ; findTriangle ( arr , n ) ; } }
Check whether a point exists in circle sector or not . | C # program to check if a point lies inside a circle sector . ; calculate endAngle ; Calculate polar co - ordinates ; Check whether polarradius is less then radius of circle or not and Angle is between startAngle and endAngle or not ; Driver code
using System . IO ; using System ; class GFG { static void checkPoint ( int radius , int x , int y , float percent , float startAngle ) { float endAngle = 360 / percent + startAngle ; float polarradius = ( float ) Math . Sqrt ( x * x + y * y ) ; float Angle = ( float ) Math . Atan ( y / x ) ; if ( Angle >= startAngle && Angle <= endAngle && polarradius < radius ) Console . Write ( " Point ▁ ( { 0 } , ▁ { 1 } ) ▁ exist ▁ in ▁ " + " the ▁ circle ▁ sector " , x , y ) ; else Console . Write ( " Point ▁ ( { 0 } , ▁ { 1 } ) ▁ does ▁ not ▁ " + " exist ▁ in ▁ the ▁ circle ▁ sector " , x , y ) ; } public static void Main ( ) { int radius = 8 , x = 3 , y = 4 ; float percent = 12 , startAngle = 0 ; checkPoint ( radius , x , y , percent , startAngle ) ; } }
Program to find the Type of Triangle from the given Coordinates | C # program to classify a given triangle ; Utility method to return square of x ; Utility method to sort a , b , c ; after this method a <= b <= c ; Utility method to return Square of distance between two points ; Method to classify side ; if all sides are equal ; if any two sides are equal ; Method to classify angle ; If addition of sum of square of two side is less , then acute ; by pythagoras theorem ; Method to classify the triangle by sides and angles ; Find squares of distances between points ; Sort all squares of distances in increasing order ; Driver code
using System ; class GFG { public class point { public int x , y ; public point ( ) { } public point ( int x , int y ) { this . x = x ; this . y = y ; } } ; static int square ( int x ) { return x * x ; } static int a , b , c ; static void order ( ) { int [ ] copy = new int [ 3 ] ; copy [ 0 ] = a ; copy [ 1 ] = b ; copy [ 2 ] = c ; Array . Sort ( copy ) ; a = copy [ 0 ] ; b = copy [ 1 ] ; c = copy [ 2 ] ; } static int euclidDistSquare ( point p1 , point p2 ) { return square ( p1 . x - p2 . x ) + square ( p1 . y - p2 . y ) ; } static String getSideClassification ( int a , int b , int c ) { if ( a == b && b == c ) return " Equilateral " ; else if ( a == b b == c ) return " Isosceles " ; else return " Scalene " ; } static String getAngleClassification ( int a , int b , int c ) { if ( a + b > c ) return " acute " ; else if ( a + b == c ) return " right " ; else return " obtuse " ; } static void classifyTriangle ( point p1 , point p2 , point p3 ) { a = euclidDistSquare ( p1 , p2 ) ; b = euclidDistSquare ( p1 , p3 ) ; c = euclidDistSquare ( p2 , p3 ) ; order ( ) ; Console . WriteLine ( " Triangle ▁ is ▁ " + getAngleClassification ( a , b , c ) + " ▁ and ▁ " + getSideClassification ( a , b , c ) ) ; } public static void Main ( String [ ] args ) { point p1 , p2 , p3 ; p1 = new point ( 3 , 0 ) ; p2 = new point ( 0 , 4 ) ; p3 = new point ( 4 , 7 ) ; classifyTriangle ( p1 , p2 , p3 ) ; p1 = new point ( 0 , 0 ) ; p2 = new point ( 1 , 1 ) ; p3 = new point ( 1 , 2 ) ; classifyTriangle ( p1 , p2 , p3 ) ; } }
Area of a polygon with given n ordered vertices | C # program to evaluate area of a polygon using shoelace formula ; ( X [ i ] , Y [ i ] ) are coordinates of i 'th point. ; Initialize area ; Calculate value of shoelace formula ; j is previous vertex to i ; Return absolute value ; Driver program
using System ; class GFG { public static double polygonArea ( double [ ] X , double [ ] Y , int n ) { double area = 0.0 ; int j = n - 1 ; for ( int i = 0 ; i < n ; i ++ ) { area += ( X [ j ] + X [ i ] ) * ( Y [ j ] - Y [ i ] ) ; j = i ; } return Math . Abs ( area / 2.0 ) ; } public static void Main ( ) { double [ ] X = { 0 , 2 , 4 } ; double [ ] Y = { 1 , 3 , 7 } ; int n = 3 ; Console . WriteLine ( polygonArea ( X , Y , n ) ) ; } }
Find Nth root of a number using Bisection method | C # program for the above approach ; Function that returns the value of the function at a given value of x ; calculating the value of the differential of the function ; The function that returns the root of given number ; Defining range on which answer can be found ; finding mid value ; Driver code
using System ; public class GFG { static double f ( double x , int p , double num ) { return Math . Pow ( x , p ) - num ; } static double f_prime ( double x , int p ) { return p * Math . Pow ( x , p - 1 ) ; } static double root ( double num , int p ) { double left = - num ; double right = num ; double x ; while ( true ) { x = ( left + right ) / 2.0 ; double value = f ( x , p , num ) ; double prime = f_prime ( x , p ) ; if ( value * prime <= 0 ) left = x ; else right = x ; if ( value < 0.000001 && value >= 0 ) { return x ; } } } public static void Main ( string [ ] args ) { double P = 1234321 ; int N = 2 ; double ans = root ( P , N ) ; Console . Write ( ans ) ; } }
Convert 0 to N by adding 1 or multiplying by 2 in minimum steps | C # program for above approach ; Function to count number of set bits in N ; Stores the count of set bits ; If N is odd , then it a set bit ; Return the result ; Driver Code
using System ; public class GFG { static int minimumAdditionOperation ( int N ) { int count = 0 ; while ( N != 0 ) { if ( ( N & 1 ) == 1 ) { count ++ ; } N = N >> 1 ; } return count ; } static public void Main ( ) { int N = 6 ; Console . Write ( minimumAdditionOperation ( N ) ) ; } }
Minimum divide by 2 operations required to make GCD odd for given Array | C # program for the above approach ; Function to find the minimum number of operations to make the GCD of the array odd ; Stores the minimum operations required ; Stores the powers of two for the current array element ; Dividing by 2 ; Increment the count ; Update the minimum operation required ; Return the result required ; Driver Code
using System ; class GFG { public static int minimumOperations ( int [ ] arr , int N ) { int mini = Int32 . MaxValue ; for ( int i = 0 ; i < N ; i ++ ) { int count = 0 ; while ( arr [ i ] % 2 == 0 ) { arr [ i ] = arr [ i ] / 2 ; count ++ ; } if ( mini > count ) { mini = count ; } } return mini ; } public static void Main ( string [ ] args ) { int [ ] arr = { 4 , 6 } ; int N = arr . Length ; Console . WriteLine ( minimumOperations ( arr , N ) ) ; } }
Minimum size of the array with MEX as A and XOR of the array elements as B | C # program for the above approach ; Function to find the minimum size of array with given MEX and XOR ; Find the XOR of values from 0 to A - 1 ; If A is a multiple of 4 ; If A % 4 gives remainder 1 ; If A % 4 gives remainder 2 ; Initializing array size by A ; If XOR of all values of array is equal to B ; If the required integer to be added is equal to A ; Else any integer can be added ; Driver Code
using System ; public class GFG { static int minimumSizeArr ( int A , int B ) { int currXor = 0 ; int reminder = ( A - 1 ) % 4 ; if ( reminder == 0 ) currXor = A - 1 ; else if ( reminder == 1 ) currXor = 1 ; else if ( reminder == 2 ) currXor = A ; int minSize = A ; if ( currXor == B ) return minSize ; else if ( ( currXor ^ B ) == A ) return minSize + 2 ; else return minSize + 1 ; } public static void Main ( ) { int A = 1 ; int B = 999 ; Console . WriteLine ( minimumSizeArr ( A , B ) ) ; } }
Count of triplets till N whose product is at most N | C # program for the above approach ; Function to find number of triplets ( A , B , C ) having A * B * C <= N ; Stores the count of triplets ; Iterate a loop fixing the value of A ; Iterate a loop fixing the value of A ; Find the total count of triplets and add it to cnt ; Return the total triplets formed ; Driver Code
using System ; public class GFG { static int countTriplets ( int N ) { int cnt = 0 ; for ( int A = 1 ; A <= N ; ++ A ) { for ( int B = 1 ; B <= N / A ; ++ B ) { cnt += N / ( A * B ) ; } } return cnt ; } public static void Main ( string [ ] args ) { int N = 2 ; Console . WriteLine ( countTriplets ( N ) ) ; } }
Largest integer upto N having greatest prime factor greater than its square root | C # program for the above approach ; Stores the Greatest Prime Factor ; Modified Sieve to find the Greatest Prime Factor of all integers in the range [ 1 , maxn ] ; Initialize the array with 0 ; Iterate through all values of i ; If i is not a prime number ; Update the multiples of i ; Function to find integer in the range [ 1 , N ] such that its Greatest Prime factor is greater than its square root ; Iterate through all values of i in the range [ N , 1 ] ; If greatest prime factor of i is greater than its sqare root ; Return answer ; If no valid integer exist ; Driver Code
using System ; public class GFG { static int maxn = 100001 ; static int [ ] gpf = new int [ maxn ] ; static void modifiedSieve ( ) { for ( int i = 0 ; i < maxn ; i ++ ) gpf [ i ] = 0 ; gpf [ 0 ] = 0 ; gpf [ 1 ] = 1 ; for ( int i = 2 ; i < maxn ; i ++ ) { if ( gpf [ i ] > 0 ) continue ; for ( int j = i ; j < maxn ; j += i ) { gpf [ j ] = Math . Max ( i , gpf [ j ] ) ; } } } static int greatestValidInt ( int N ) { modifiedSieve ( ) ; for ( int i = N ; i > 0 ; i -- ) { if ( gpf [ i ] > Math . Sqrt ( i ) ) { return i ; } } return - 1 ; } public static void Main ( string [ ] args ) { int N = 25 ; Console . WriteLine ( greatestValidInt ( N ) ) ; } }