codeparrot/xlcost-text-to-code huggingface dataset:
Program to print the series 2 , 15 , 41 , 80 , 132 , 197 … till N terms | Function to print the series ; Generate the ith term and ; Driver Code
def printSeries ( N ) : NEW_LINE INDENT ith_term = 0 ; NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT ith_term = ( 13 * i * ( i - 1 ) ) / 2 + 2 ; NEW_LINE print ( int ( ith_term ) , " , ▁ " , end = " " ) ; NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 7 ; NEW_LINE printSeries ( N ) ; NEW_LINE DEDENT
Possible pairs forming a Pythagorean Triple with a given value | Function to generate all possible pairs ; Vector to store all the possible pairs ; Checking all the possible pair in the range of [ 1 , c ) ; If the pair satisfies the condition push it in the vector ; Driver code ; If no valid pair exist ; Print all valid pairs
def Pairs ( C ) : NEW_LINE INDENT ans = [ ] NEW_LINE for i in range ( C ) : NEW_LINE INDENT for j in range ( i + 1 , C ) : NEW_LINE INDENT if ( ( i * i ) + ( j * j ) == ( C * C ) ) : NEW_LINE INDENT ans . append ( [ i , j ] ) NEW_LINE DEDENT DEDENT DEDENT return ans ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT C = 13 ; NEW_LINE ans = Pairs ( C ) ; NEW_LINE if ( len ( ans ) == 0 ) : NEW_LINE INDENT print ( " No ▁ valid ▁ pair ▁ exist " ) NEW_LINE exit ( ) NEW_LINE DEDENT for i in range ( len ( ans ) ) : NEW_LINE INDENT print ( " ( " + str ( ans [ i ] [ 0 ] ) + " , ▁ " + str ( ans [ i ] [ 1 ] ) + " ) " ) NEW_LINE DEDENT DEDENT
How to calculate strike rate of a batsman | function to calculate strike rate of a batsman ; Driver Code
def strikerate ( bowls , runs ) : NEW_LINE INDENT z = ( float ( runs ) / bowls ) * 100 ; NEW_LINE return z ; NEW_LINE DEDENT A = 264 ; NEW_LINE B = 173 ; NEW_LINE print ( strikerate ( B , A ) ) ; NEW_LINE
Check if a number exists with X divisors out of which Y are composite | Python3 program to check if a number exists having exactly X positive divisors out of which Y are composite divisors ; Count the number of times 2 divides N ; Check for all possible numbers that can divide it ; If N at the end is a prime number . ; Function to check if any such number exists ; Driver Code
import math NEW_LINE def factorize ( N ) : NEW_LINE INDENT count = 0 NEW_LINE cnt = 0 NEW_LINE while ( ( N % 2 ) == 0 ) : NEW_LINE INDENT N = N // 2 NEW_LINE count += 1 NEW_LINE DEDENT cnt = cnt + count NEW_LINE sq = int ( math . sqrt ( N ) ) NEW_LINE for i in range ( 3 , sq , 2 ) : NEW_LINE INDENT count = 0 NEW_LINE while ( N % i == 0 ) : NEW_LINE INDENT count += 1 NEW_LINE N = N // i NEW_LINE DEDENT cnt = cnt + count NEW_LINE DEDENT if ( N > 2 ) : NEW_LINE INDENT cnt = cnt + 1 NEW_LINE DEDENT return cnt NEW_LINE DEDENT def ifNumberExists ( X , Y ) : NEW_LINE INDENT C = X - Y - 1 NEW_LINE dsum = factorize ( X ) NEW_LINE if ( dsum >= C ) : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT X = 6 NEW_LINE Y = 4 NEW_LINE ifNumberExists ( X , Y ) NEW_LINE DEDENT
Nearest prime number in the array of every array element | Python3 program to find nearest prime number in the array for all array elements ; Create a boolean array and set all entries it as false . A value in prime [ i ] will be true if i is not a prime , else false ; Sieve of Eratosthenes function ; Update all multiples of i greater than or equal to the square of it numbers which are multiple of i and are less than i ^ 2 are already been marked . ; Function to find nearest prime number for all elements ; Compute and store all prime numbers up to maxm ; Store the indices of all primes ; If no primes are present in the array ; Store the current prime ; If the no further primes exist in the array ; For all indices less than that of the current prime ; If the current prime is nearer ; If the next prime is nearer ; Make the next prime as the current ; Driver code
maxi = 10000000 NEW_LINE prime = [ False ] * ( maxi ) NEW_LINE def SieveOfEratosthenes ( maxm ) : NEW_LINE INDENT prime [ 0 ] = prime [ 1 ] = True NEW_LINE for i in range ( 2 , maxm + 1 ) : NEW_LINE INDENT if i * i > maxm : NEW_LINE INDENT break NEW_LINE DEDENT if ( not prime [ i ] ) : NEW_LINE INDENT for j in range ( i * i , maxm + 1 , i ) : NEW_LINE INDENT prime [ j ] = True NEW_LINE DEDENT DEDENT DEDENT DEDENT def print_nearest_prime ( arr , N ) : NEW_LINE INDENT maxm = max ( arr ) NEW_LINE SieveOfEratosthenes ( maxm ) NEW_LINE primes = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( not prime [ arr [ i ] ] ) : NEW_LINE INDENT primes . append ( i ) NEW_LINE DEDENT DEDENT if len ( primes ) == 0 : NEW_LINE INDENT for i in range ( N ) : NEW_LINE INDENT print ( - 1 , end = " ▁ " ) NEW_LINE DEDENT return NEW_LINE DEDENT curr = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( curr == len ( primes ) - 1 or i <= primes [ curr ] ) : NEW_LINE INDENT print ( arr [ primes [ curr ] ] , end = " ▁ " ) NEW_LINE continue NEW_LINE DEDENT if ( abs ( primes [ curr ] - i ) < abs ( primes [ curr + 1 ] - i ) ) : NEW_LINE INDENT print ( arr [ primes [ curr ] ] , end = " ▁ " ) NEW_LINE DEDENT else : NEW_LINE INDENT curr += 1 NEW_LINE print ( arr [ primes [ curr ] ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 6 NEW_LINE arr = [ 8 , 7 , 12 , 15 , 3 , 11 ] NEW_LINE print_nearest_prime ( arr , N ) NEW_LINE DEDENT
Find position of given term in a series formed with only digits 4 and 7 allowed | Function to find the position of the number N ; To store the position of N ; Iterate through all digit of N ; If current digit is 7 ; If current digit is 4 ; Print the final position ; Driver Code ; Given number of the series ; Function Call
def findPosition ( n ) : NEW_LINE INDENT i = 0 NEW_LINE pos = 0 NEW_LINE while ( n > 0 ) : NEW_LINE INDENT if ( n % 10 == 7 ) : NEW_LINE INDENT pos = pos + pow ( 2 , i + 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT pos = pos + pow ( 2 , i ) NEW_LINE DEDENT i += 1 NEW_LINE n = n // 10 NEW_LINE DEDENT print ( pos ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 777 NEW_LINE findPosition ( N ) NEW_LINE DEDENT
Average of Cubes of first N natural numbers | Function to find average of cubes ; Storing sum of cubes of numbers in sum ; Calculate sum of cubes ; Return average ; Driver Code ; Given Number ; Function Call
def findAverageOfCube ( n ) : NEW_LINE INDENT sum = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT sum += i * i * i NEW_LINE DEDENT return round ( sum / n , 6 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 3 NEW_LINE print ( findAverageOfCube ( n ) ) NEW_LINE DEDENT
Smallest and Largest N | Python3 program for the above approach ; Function to find n digit largest number starting and ending with n ; Corner Case when n = 1 ; Result will store the n - 2 * length ( n ) digit largest number ; Find the number of digits in number n ; Append 9 ; To make it largest n digit number starting and ending with n , we just need to append n at start and end ; Return the largest number ; Function to find n digit smallest number starting and ending with n ; Corner Case when n = 1 ; Result will store the n - 2 * length ( n ) digit smallest number ; Find the number of digits in number n ; To make it smallest n digit number starting and ending with n , we just need to append n at start and end ; Return the smallest number ; Driver Code ; Given Number ; Function Call
import math NEW_LINE def findNumberL ( n ) : NEW_LINE INDENT if ( n == 1 ) : NEW_LINE INDENT return "1" NEW_LINE DEDENT result = " " NEW_LINE length = math . floor ( math . log10 ( n ) + 1 ) NEW_LINE for i in range ( 1 , n - ( 2 * length ) + 1 ) : NEW_LINE INDENT result += '9' NEW_LINE DEDENT result = ( str ( n ) + result + str ( n ) ) NEW_LINE return result NEW_LINE DEDENT def findNumberS ( n ) : NEW_LINE INDENT if ( n == 1 ) : NEW_LINE INDENT return "1" NEW_LINE DEDENT result = " " NEW_LINE length = math . floor ( math . log10 ( n ) + 1 ) NEW_LINE for i in range ( 1 , n - ( 2 * length ) + 1 ) : NEW_LINE INDENT result += '0' NEW_LINE DEDENT result = ( str ( n ) + result + str ( n ) ) NEW_LINE return result NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 3 NEW_LINE print ( " Smallest ▁ Number ▁ = ▁ " + findNumberS ( N ) ) NEW_LINE print ( " Largest ▁ Number ▁ = ▁ " + findNumberL ( N ) ) NEW_LINE DEDENT
Maximum number of 0 s that can be flipped such that Array has no adjacent 1 s | Maximum number of 0 s that can be replaced by 1 ; Check for three consecutive 0 s ; Flip the bit ; Increase the count ; Driver code
def canReplace ( arr , n ) : NEW_LINE INDENT i = 0 NEW_LINE count = 0 NEW_LINE while ( i < n ) : NEW_LINE INDENT if ( arr [ i ] == 0 and ( i == 0 or arr [ i - 1 ] == 0 ) and ( i == n - 1 or arr [ i + 1 ] == 0 ) ) : NEW_LINE INDENT arr [ i ] = 1 NEW_LINE count += 1 NEW_LINE DEDENT i += 1 NEW_LINE DEDENT return count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 0 , 0 , 0 , 1 ] NEW_LINE print ( canReplace ( arr , 5 ) ) NEW_LINE DEDENT
Sum of first N Star Numbers | Function to find the sum of the first N star number ; Variable to store the sum ; Driver code
def sum_star_num ( n ) : NEW_LINE INDENT summ = 2 * n * ( n + 1 ) * ( n - 1 ) + n NEW_LINE return summ NEW_LINE DEDENT n = 3 NEW_LINE print ( sum_star_num ( n ) ) NEW_LINE
Count distinct median possible for an Array using given ranges of elements | Function to count the number of distinct medians of an array where each array elements are given by a range ; Loop to store the starting and end range in the array ; Condition to check if the length of the array is odd ; Driver Code ; Function Call
def solve ( n , vec ) : NEW_LINE INDENT a = [ ] NEW_LINE b = [ ] NEW_LINE for pr in vec : NEW_LINE INDENT a . append ( pr [ 0 ] ) NEW_LINE b . append ( pr [ 1 ] ) NEW_LINE DEDENT a . sort ( ) NEW_LINE b . sort ( ) NEW_LINE if ( ( n & 1 ) ) : NEW_LINE INDENT left = a [ n // 2 ] NEW_LINE right = b [ n // 2 ] NEW_LINE ans = right - left + 1 NEW_LINE DEDENT else : NEW_LINE INDENT left = ( a [ n // 2 ] + a [ n // 2 - 1 ] ) NEW_LINE right = ( b [ n // 2 ] + b [ n // 2 - 1 ] ) NEW_LINE ans = right - left + 1 NEW_LINE DEDENT print ( ans ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 3 NEW_LINE vec = [ ( 100 , 100 ) , ( 10 , 10000 ) , ( 1 , 1000000000 ) ] NEW_LINE solve ( N , vec ) NEW_LINE DEDENT
Count of pairs from Array with sum equal to twice their bitwise AND | Python3 implementation to find the pairs with equal sum and twice the bitwise AND of the pairs ; Map to store the occurrence of elements of array ; Function to find the pairs with equal sum and twice the bitwise AND of the pairs ; Loop to find the frequency of elements of array ; Function to find the count such pairs in the array ; If an element occurs more than once then the answer will by incremented by nC2 times ; Driver Code ; Function Call
from collections import defaultdict NEW_LINE mp = defaultdict ( int ) NEW_LINE def find_pairs ( arr , n ) : NEW_LINE INDENT ans = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT mp [ arr [ i ] ] += 1 NEW_LINE DEDENT for i in mp . values ( ) : NEW_LINE INDENT count = i NEW_LINE if ( count > 1 ) : NEW_LINE INDENT ans += ( ( count * ( count - 1 ) ) // 2 ) NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 2 , 3 , 3 , 4 , 5 , 5 , 7 , 8 ] NEW_LINE arr_size = len ( arr ) NEW_LINE print ( find_pairs ( arr , arr_size ) ) NEW_LINE DEDENT
360 | Function to find the nth 360 - gon Number ; Driver Code
def gonNum360 ( n ) : NEW_LINE INDENT return ( 358 * n * n - 356 * n ) // 2 ; NEW_LINE DEDENT n = 3 ; NEW_LINE print ( gonNum360 ( n ) ) ; NEW_LINE
120 | Function to find the nth 120 - gon Number ; Driver Code
def gonNum120 ( n ) : NEW_LINE INDENT return ( 118 * n * n - 116 * n ) // 2 ; NEW_LINE DEDENT n = 3 ; NEW_LINE print ( gonNum120 ( n ) ) ; NEW_LINE
Tetracontaoctagonal Number | Function to find the nth Tetracontaoctagonal Number ; Driver Code
def TetracontaoctagonalNum ( n ) : NEW_LINE INDENT return ( 46 * n * n - 44 * n ) / 2 ; NEW_LINE DEDENT n = 3 ; NEW_LINE print ( TetracontaoctagonalNum ( n ) ) ; NEW_LINE
257 | Function to find the nth 257 - gon Number ; Driver Code
def gonNum257 ( n ) : NEW_LINE INDENT return ( 255 * n * n - 253 * n ) // 2 ; NEW_LINE DEDENT n = 3 ; NEW_LINE print ( gonNum257 ( n ) ) ; NEW_LINE
Tetracontadigonal Number | Function to find the nth tetracontadigonal number ; Driver Code
def TetracontadigonalNum ( n ) : NEW_LINE INDENT return int ( ( 40 * n * n - 38 * n ) / 2 ) NEW_LINE DEDENT n = 3 NEW_LINE print ( TetracontadigonalNum ( n ) ) NEW_LINE
Index of smallest triangular number with N digits | Python3 implementation of the above approach ; Function to return index of smallest triangular no n digits ; Driver Code
import math NEW_LINE def findIndex ( n ) : NEW_LINE INDENT x = math . sqrt ( 2 * math . pow ( 10 , ( n - 1 ) ) ) ; NEW_LINE return round ( x ) ; NEW_LINE DEDENT n = 3 ; NEW_LINE print ( findIndex ( n ) ) ; NEW_LINE
Program to find the LCM of two prime numbers | Function to return the LCM of two prime numbers ; If the two numbers are equal then return any one of a and b ; Else return product of the numbers ; Driver code ; Given two numbers ; Function Call
def findLCMPrime ( a , b ) : NEW_LINE INDENT if ( a == b ) : NEW_LINE INDENT return a ; NEW_LINE DEDENT return a * b ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a = 3 ; b = 5 ; NEW_LINE print ( findLCMPrime ( a , b ) ) ; NEW_LINE DEDENT
Smallest multiple of N with exactly N digits in its Binary number representation | Python3 program to find smallest multiple of n with exactly N digits in Binary number System . ; Function to find smallest multiple of n with exactly n digits in Binary number representation . ; Driver code
from math import ceil NEW_LINE def smallestNumber ( N ) : NEW_LINE INDENT print ( N * ceil ( pow ( 2 , ( N - 1 ) ) / N ) ) NEW_LINE DEDENT N = 3 NEW_LINE smallestNumber ( N ) NEW_LINE
Find the largest N digit multiple of N | Python3 program to find largest multiple of N containing N digits ; Function to find the largest N digit multiple of N ; Driver code
from math import floor NEW_LINE def smallestNumber ( N ) : NEW_LINE INDENT print ( N * floor ( ( pow ( 10 , N ) - 1 ) / N ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 2 NEW_LINE smallestNumber ( N ) NEW_LINE DEDENT
Icosikaiheptagonal Number | Function to find the nth icosikaiheptagonal Number ; Driver code
def icosikaiheptagonalNum ( n ) : NEW_LINE INDENT return ( 25 * n * n - 23 * n ) // 2 ; NEW_LINE DEDENT n = 3 ; NEW_LINE print ( "3rd ▁ icosikaiheptagonal ▁ Number ▁ is ▁ " , icosikaiheptagonalNum ( n ) ) ; NEW_LINE
Program to check if N is a triacontagonal number | Python3 program to check whether a number is an triacontagonal number or not ; Function to check whether a number is an triacontagonal number or not ; Condition to check whether a number is an triacontagonal number or not ; Given number ; Function call
import math ; NEW_LINE def istriacontagonal ( N ) : NEW_LINE INDENT n = ( 26 + math . sqrt ( 224 * N + 676 ) ) // 56 ; NEW_LINE return ( n - int ( n ) ) == 0 ; NEW_LINE DEDENT i = 30 ; NEW_LINE if ( istriacontagonal ( i ) ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT
Check whether one root of the Quadratic Equation is twice of other or not | Function to find the required answer ; Driver code
def checkSolution ( a , b , c ) : NEW_LINE INDENT if ( 2 * b * b == 9 * a * c ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT DEDENT a = 1 ; b = 3 ; c = 2 ; NEW_LINE checkSolution ( a , b , c ) ; NEW_LINE
Parity of the given mathematical expression using given N numbers | Python3 program to determine the parity of the given mathematical expression ; Iterating through the given integers ; If any odd number is present , then S is even parity ; Else , S is odd parity ; Driver code
def getParity ( n , A ) : NEW_LINE INDENT for x in A : NEW_LINE INDENT if ( x & 1 ) : NEW_LINE INDENT print ( " Even " ) NEW_LINE return NEW_LINE DEDENT DEDENT print ( " Odd " ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 3 NEW_LINE A = [ 2 , 3 , 1 ] NEW_LINE getParity ( N , A ) NEW_LINE DEDENT
Count of digits after concatenation of first N positive integers | Python3 program to find the number of digits after concatenating the first N positive integers ; Function to find the number of digits after concatenating the first N positive integers ; Driver code
from math import log10 , floor NEW_LINE def numberOfDigits ( N ) : NEW_LINE INDENT nod = floor ( log10 ( N ) + 1 ) ; NEW_LINE toDecrease = ( pow ( 10 , nod ) - 1 ) // 9 NEW_LINE print ( ( N + 1 ) * nod - toDecrease ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 13 NEW_LINE numberOfDigits ( N ) NEW_LINE DEDENT
Length of maximum product subarray | function that returns the maximum length subarray having non zero product ; zeroindex list to store indexex of zero ; if zeroindex list is empty then Maxlength is as size of array ; if zeroindex list is not empty ; first zero is on index 2 that means two numbers positive , before index 2 so as their product is positive to ; checking for other indexex ; if the difference is greater than maxlen then maxlen is updated ; to check the length of remaining array after last zeroindex ; Driver Code
def Maxlength ( arr , N ) : NEW_LINE INDENT zeroindex = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( arr [ i ] == 0 ) : NEW_LINE INDENT zeroindex . append ( i ) NEW_LINE DEDENT DEDENT if ( len ( zeroindex ) == 0 ) : NEW_LINE INDENT maxlen = N NEW_LINE DEDENT else : NEW_LINE INDENT maxlen = zeroindex [ 0 ] NEW_LINE for i in range ( 0 , len ( zeroindex ) - 1 ) : NEW_LINE INDENT if ( zeroindex [ i + 1 ] \ - zeroindex [ i ] - 1 \ > maxlen ) : NEW_LINE INDENT maxlen = zeroindex [ i + 1 ] - zeroindex [ i ] - 1 NEW_LINE DEDENT DEDENT if ( N - zeroindex [ len ( zeroindex ) - 1 ] \ - 1 > maxlen ) : NEW_LINE INDENT maxlen = N - zeroindex [ len ( zeroindex ) - 1 ] - 1 NEW_LINE DEDENT DEDENT print ( maxlen ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 9 NEW_LINE arr = [ 7 , 1 , 0 , 1 , 2 , 0 , 9 , 2 , 1 ] NEW_LINE Maxlength ( arr , N ) NEW_LINE DEDENT
Check if sum of exactly K elements of the Array can be odd or not | Function returns true if it is possible to have odd sum ; Counting number of odd and even elements ; Driver code
def isPossible ( arr , N , K ) : NEW_LINE INDENT oddCount = 0 NEW_LINE evenCount = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( arr [ i ] % 2 == 0 ) : NEW_LINE INDENT evenCount += 1 NEW_LINE DEDENT else : NEW_LINE INDENT oddCount += 1 NEW_LINE DEDENT DEDENT if ( evenCount == N or ( oddCount == N and K % 2 == 0 ) or ( K == N and oddCount % 2 == 0 ) ) : NEW_LINE INDENT return False NEW_LINE DEDENT else : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 2 , 3 , 4 , 5 , 8 ] NEW_LINE K = 5 NEW_LINE N = len ( arr ) NEW_LINE if ( isPossible ( arr , N , K ) ) : NEW_LINE INDENT print ( " Possible " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Not ▁ Possible " ) NEW_LINE DEDENT DEDENT
Find the last two digits of Factorial of a given Number | Function to print the last two digits of N ! ; For N >= 10 , N ! % 100 will always be 0 ; Calculating N ! % 100 ; Driver code
def lastTwoDigits ( N ) : NEW_LINE INDENT if ( N >= 10 ) : NEW_LINE INDENT print ( "00" , end = " " ) NEW_LINE return NEW_LINE DEDENT fac = 1 NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT fac = ( fac * i ) % 100 NEW_LINE DEDENT print ( fac ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 7 NEW_LINE lastTwoDigits ( N ) NEW_LINE DEDENT
Product of N terms of a given Geometric series | Function to calculate product of geometric series ; Return the final product with the above formula ; Given first term and common ratio ; Number of terms ; Function Call
def productOfGP ( a , r , n ) : NEW_LINE INDENT return pow ( a , n ) * pow ( r , n * ( n - 1 ) // 2 ) ; NEW_LINE DEDENT a = 1 ; r = 2 ; NEW_LINE N = 4 ; NEW_LINE print ( productOfGP ( a , r , N ) ) ; NEW_LINE
Product of N terms of a given Geometric series | Python3 program for the above approach ; Function to calculate product of N terms of geometric series ; Find the product of first and the last term ; Return the sqrt of the above expression to find the product ; Given first term and common ratio ; Number of terms ; Function Call
import math NEW_LINE def productOfGP ( a , r , n ) : NEW_LINE INDENT an = a * pow ( r , n - 1 ) ; NEW_LINE return ( math . sqrt ( pow ( a * an , n ) ) ) NEW_LINE DEDENT a = 1 NEW_LINE r = 2 ; NEW_LINE N = 4 ; NEW_LINE print ( productOfGP ( a , r , N ) ) NEW_LINE
Find two numbers such that difference of their squares equal to N | Python3 Program to find two numbers with difference of their squares equal to N ; Function to check and print the required two positive integers ; Iterate till sqrt ( n ) to find factors of N ; Check if x is one of the factors of N ; Store the factor ; Compute the other factor ; Check if the two factors are of the same parity ; Compute a and b ; If no pair exists ; Driver Code
from math import sqrt NEW_LINE def solve ( n ) : NEW_LINE INDENT for x in range ( 1 , int ( sqrt ( n ) ) + 1 ) : NEW_LINE INDENT if ( n % x == 0 ) : NEW_LINE INDENT small = x ; NEW_LINE big = n // x ; NEW_LINE if ( small % 2 == big % 2 ) : NEW_LINE INDENT a = ( small + big ) // 2 ; NEW_LINE b = ( big - small ) // 2 ; NEW_LINE print ( a , b ) ; NEW_LINE return ; NEW_LINE DEDENT DEDENT DEDENT print ( - 1 ) ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 7 ; NEW_LINE solve ( n ) ; NEW_LINE DEDENT
Probability that an arbitrary positive divisor of 10 ^ X is an integral multiple of 10 ^ Y | Python3 program to find the probability of an arbitrary positive divisor of Xth power of 10 to be a multiple of Yth power of 10 ; Function to calculate and print the required probability ; Count of potential divisors of X - th power of 10 which are also multiples of Y - th power of 10 ; Count of divisors of X - th power of 10 ; Calculate GCD ; Print the reduced fraction probability ; Driver Code
from math import * NEW_LINE def prob ( x , y ) : NEW_LINE INDENT num = abs ( x - y + 1 ) * abs ( x - y + 1 ) NEW_LINE den = ( x + 1 ) * ( x + 1 ) NEW_LINE gcd1 = gcd ( num , den ) NEW_LINE print ( num // gcd1 , end = " " ) NEW_LINE print ( " / " , end = " " ) NEW_LINE print ( den // gcd1 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT X = 2 NEW_LINE Y = 1 NEW_LINE prob ( X , Y ) NEW_LINE DEDENT
Program to check if N is a Chiliagon Number | Python3 for the above approach ; Function to check that if N is Chiliagon Number or not ; Condition to check if N is a Chiliagon Number ; Given Number ; Function call
import math ; NEW_LINE def is_Chiliagon ( N ) : NEW_LINE INDENT n = ( 996 + math . sqrt ( 7984 * N + 992016 ) ) // 1996 ; NEW_LINE return ( n - int ( n ) ) == 0 ; NEW_LINE DEDENT N = 1000 ; NEW_LINE if ( is_Chiliagon ( N ) ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT