codeparrot/xlcost-text-to-code huggingface dataset:
Highly Composite Numbers | Function to count the number of divisors of the N ; Sieve method for prime calculation ; Traversing through all prime numbers ; Calculate number of divisor with formula total div = ( p1 + 1 ) * ( p2 + 1 ) * ... . . * ( pn + 1 ) where n = ( a1 ^ p1 ) * ( a2 ^ p2 ) . ... * ( an ^ pn ) ai being prime divisor for n and pi are their respective power in factorization ; Function to check if a number is a highly composite number ; Count number of factors of N ; Loop to count number of factors of every number less than N ; If any number less than N has more factors than N , then return false ; Given Number N ; Function Call
def divCount ( n ) : NEW_LINE INDENT Hash = [ True for i in range ( n + 1 ) ] NEW_LINE p = 2 NEW_LINE while ( ( p * p ) < n ) : NEW_LINE INDENT if bool ( Hash [ p ] ) : NEW_LINE INDENT i = p * 2 NEW_LINE while i < n : NEW_LINE INDENT Hash [ i ] = False NEW_LINE i += p NEW_LINE DEDENT DEDENT p += 1 NEW_LINE DEDENT total = 1 NEW_LINE for P in range ( 2 , n + 1 ) : NEW_LINE INDENT if ( bool ( Hash [ P ] ) ) : NEW_LINE INDENT count = 0 NEW_LINE if ( n % P == 0 ) : NEW_LINE INDENT while ( n % P == 0 ) : NEW_LINE INDENT n = n // P NEW_LINE count += 1 NEW_LINE DEDENT total = total * ( count + 1 ) NEW_LINE DEDENT DEDENT DEDENT return total NEW_LINE DEDENT def isHighlyCompositeNumber ( N ) : NEW_LINE INDENT NdivCount = divCount ( N ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT idivCount = divCount ( i ) NEW_LINE if ( idivCount >= NdivCount ) : NEW_LINE INDENT return bool ( False ) NEW_LINE DEDENT DEDENT return bool ( True ) NEW_LINE DEDENT N = 12 NEW_LINE if ( bool ( isHighlyCompositeNumber ( N ) ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT
Pentacontahenagon Number | Function to find the N - th Pentacontahenagon Number ; Driver Code ; Function Call
def PentacontahenagonNum ( N ) : NEW_LINE INDENT return ( 49 * N * N - 47 * N ) // 2 ; NEW_LINE DEDENT N = 3 ; NEW_LINE print ( "3rd ▁ Pentacontahenagon ▁ Number ▁ is " , PentacontahenagonNum ( N ) ) ; NEW_LINE
Saint | Function to check if a number is a Saint - Exupery number ; Considering triplets in sorted order . The value of first element in sorted triplet can be at - most n / 3. ; The value of second element must be less than equal to n / 2 ; Given Number N ; Function Call
def isSaintExuperyNum ( n ) : NEW_LINE INDENT for i in range ( 1 , ( n // 3 ) + 1 ) : NEW_LINE INDENT for j in range ( i + 1 , ( n // 2 ) + 1 ) : NEW_LINE INDENT k = n / i / j NEW_LINE if i * i + j * j == k * k : NEW_LINE INDENT if i * j * k == n : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT DEDENT DEDENT return False NEW_LINE DEDENT N = 60 NEW_LINE if isSaintExuperyNum ( N ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT
Repdigit Numbers | Function to check if a number is a Repdigit number ; To store previous digit ( Assigning initial value which is less than any digit ) ; Traverse all digits from right to left and check if any digit is smaller than previous . ; Driver code
def isRepdigit ( num , b ) : NEW_LINE INDENT prev = - 1 NEW_LINE while ( num ) : NEW_LINE INDENT digit = num % b NEW_LINE num //= b NEW_LINE if ( prev != - 1 and digit != prev ) : NEW_LINE INDENT return False NEW_LINE DEDENT prev = digit NEW_LINE DEDENT return True NEW_LINE DEDENT num = 2000 NEW_LINE base = 7 NEW_LINE if ( isRepdigit ( num , base ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT
Enlightened Numbers | Python3 implementation of the above approach ; Function to check if N is a Composite Number ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Function to return concatenation of distinct prime factors of a given number n ; Handle prime factor 2 explicitly so that can optimally handle other prime factors . ; n must be odd at this point . So we can skip one element ( Note i = i + 2 ) ; While i divides n , print i and divide n ; This condition is to handle the case when n is a prime number greater than 2 ; Function to check if a number is is an enlightened number ; Number should not be prime ; Converting N to string ; Function call ; Driver code
import math NEW_LINE def isComposite ( n ) : NEW_LINE INDENT if n <= 3 : NEW_LINE INDENT return False NEW_LINE DEDENT if ( n % 2 == 0 or n % 3 == 0 ) : NEW_LINE INDENT return True NEW_LINE DEDENT i = 5 NEW_LINE while ( i * i <= n ) : NEW_LINE INDENT if ( n % i == 0 or n % ( i + 2 ) == 0 ) : NEW_LINE INDENT return True NEW_LINE DEDENT i = i + 6 NEW_LINE DEDENT return False NEW_LINE DEDENT def concatenatePrimeFactors ( n ) : NEW_LINE INDENT concatenate = " " NEW_LINE if ( n % 2 == 0 ) : NEW_LINE INDENT concatenate += "2" NEW_LINE while ( n % 2 == 0 ) : NEW_LINE INDENT n = int ( n / 2 ) NEW_LINE DEDENT DEDENT i = 3 NEW_LINE while ( i <= int ( math . sqrt ( n ) ) ) : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT concatenate += str ( i ) NEW_LINE while ( n % i == 0 ) : NEW_LINE INDENT n = int ( n / i ) NEW_LINE DEDENT DEDENT i = i + 2 NEW_LINE DEDENT if ( n > 2 ) : NEW_LINE INDENT concatenate += str ( n ) NEW_LINE DEDENT return concatenate NEW_LINE DEDENT def isEnlightened ( N ) : NEW_LINE INDENT if ( not isComposite ( N ) ) : NEW_LINE INDENT return False NEW_LINE DEDENT num = str ( N ) NEW_LINE prefixConc = concatenatePrimeFactors ( N ) NEW_LINE return int ( prefixConc ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 250 NEW_LINE if ( isEnlightened ( n ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT
Second Pentagonal numbers | Function to find N - th term in the series ; Driver code
def findNthTerm ( n ) : NEW_LINE INDENT print ( n * ( 3 * n + 1 ) // 2 , end = " ▁ " ) ; NEW_LINE DEDENT N = 4 ; NEW_LINE findNthTerm ( N ) ; NEW_LINE
Idoneal Numbers | Function to check if number is an Idoneal numbers ; Iterate for all triples pairs ( a , b , c ) ; If the condition is satisfied ; Driver Code ; Function call
def isIdoneal ( n ) : NEW_LINE INDENT for a in range ( 1 , n + 1 ) : NEW_LINE INDENT for b in range ( a + 1 , n + 1 ) : NEW_LINE INDENT for c in range ( b + 1 , n + 1 ) : NEW_LINE INDENT if ( a * b + b * c + c * a == n ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT DEDENT DEDENT return True NEW_LINE DEDENT N = 10 NEW_LINE if ( isIdoneal ( N ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT
Lynch | Python3 implementation for the above approach ; Function to check the divisibility of the number by its digit . ; If the digit divides the number then return true else return false . ; Function to check if all digits of n divide it or not ; Taking the digit of the number into digit var . ; Function to check if N has all distinct digits ; Create an array of size 10 and initialize all elements as false . This array is used to check if a digit is already seen or not . ; Traverse through all digits of given number ; Find the last digit ; If digit is already seen , return false ; Mark this digit as seen ; Remove the last digit from number ; Function to check Lynch - Bell numbers ; Driver Code ; Given number N ; Function call
import math NEW_LINE def checkDivisibility ( n , digit ) : NEW_LINE INDENT return ( ( digit != 0 ) and ( ( n % digit ) == 0 ) ) NEW_LINE DEDENT def isAllDigitsDivide ( n ) : NEW_LINE INDENT temp = n NEW_LINE while ( temp >= 1 ) : NEW_LINE INDENT digit = int ( temp % 10 ) NEW_LINE if ( checkDivisibility ( n , digit ) == False ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT temp = temp / 10 NEW_LINE DEDENT return 1 NEW_LINE DEDENT def isAllDigitsDistinct ( n ) : NEW_LINE INDENT arr = [ 0 ] * 10 NEW_LINE while ( n >= 1 ) : NEW_LINE INDENT digit = int ( n % 10 ) NEW_LINE if ( arr [ digit ] ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT arr [ digit ] = 1 NEW_LINE n = int ( n / 10 ) NEW_LINE DEDENT return 1 NEW_LINE DEDENT def isLynchBell ( n ) : NEW_LINE INDENT return ( isAllDigitsDivide ( n ) and isAllDigitsDistinct ( n ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 12 NEW_LINE if isLynchBell ( N ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT
Repunit numbers | Function to check if a number contains all the digits 0 , 1 , . . , ( b - 1 ) an equal number of times ; to store number of digits of n in base B ; to count frequency of digit 1 ; condition to check three or more 1 's  and number of ones is equal to number  of digits of n in base B ; Driver Code ; taking inputs ; function to check
def isRepunitNum ( n , b ) : NEW_LINE INDENT length = 0 ; NEW_LINE countOne = 0 ; NEW_LINE while ( n != 0 ) : NEW_LINE INDENT r = n % b ; NEW_LINE length += 1 ; NEW_LINE if ( r == 1 ) : NEW_LINE INDENT countOne += 1 ; NEW_LINE DEDENT n = n // b ; NEW_LINE DEDENT return countOne >= 3 and countOne == length ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 31 ; NEW_LINE base = 2 ; NEW_LINE if ( isRepunitNum ( n , base ) ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT DEDENT
Gapful Numbers | Python3 program for the above approach ; Find the first digit ; Find total number of digits - 1 ; Find first digit ; Return first digit ; Find the last digit ; return the last digit ; A function to check Gapful numbers ; Return true if n is gapful number ; Driver Code ; Given Number ; Function Call
import math NEW_LINE def firstDigit ( n ) : NEW_LINE INDENT digits = math . log10 ( n ) NEW_LINE n = ( n / math . pow ( 10 , digits ) ) NEW_LINE return n NEW_LINE DEDENT def lastDigit ( n ) : NEW_LINE INDENT return ( n % 10 ) NEW_LINE DEDENT def isGapful ( n ) : NEW_LINE INDENT concatenation = ( firstDigit ( n ) * 10 ) + lastDigit ( n ) NEW_LINE return ( n % concatenation ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 108 NEW_LINE if ( isGapful ( n ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT
Economical Numbers | Python3 implementation to find Economical Numbers till n ; Array to store all prime less than and equal to MAX . ; Utility function for sieve of sundaram ; In general Sieve of Sundaram , produces primes smaller than ( 2 * x + 2 ) for a number given number x . Since we want primes smaller than MAX , we reduce MAX to half ; Main logic of Sundaram . Mark all numbers which do not generate prime number by doing 2 * i + 1 ; Since 2 is a prime number ; Prother primes . Remaining primes are of the form 2 * i + 1 such that marked [ i ] is false . ; Function to check if a number is a Economical number ; Count digits in original number ; Count all digits in prime factors of n pDigit is going to hold this value . ; Count powers of p in n ; If primes [ i ] is a prime factor , ; Count the power of prime factors ; Add its digits to pDigit . ; Add digits of power of prime factors to pDigit . ; If n != 1 then one prime factor still to be summed up ; If digits in prime factors is less than digits in original number then return true . Else return false . ; Finding all prime numbers before limit . These numbers are used to find prime factors .
import math NEW_LINE MAX = 10000 NEW_LINE primes = [ ] NEW_LINE def sieveSundaram ( ) : NEW_LINE INDENT marked = [ 0 ] * ( MAX // 2 + 1 ) NEW_LINE for i in range ( 1 , ( int ( math . sqrt ( MAX ) ) - 1 ) // 2 + 1 ) : NEW_LINE INDENT j = ( i * ( i + 1 ) ) << 1 NEW_LINE while ( j <= MAX // 2 ) : NEW_LINE INDENT marked [ j ] = True NEW_LINE j = j + 2 * i + 1 NEW_LINE DEDENT DEDENT primes . append ( 2 ) NEW_LINE for i in range ( 1 , MAX // 2 + 1 ) : NEW_LINE INDENT if ( marked [ i ] == False ) : NEW_LINE INDENT primes . append ( 2 * i + 1 ) NEW_LINE DEDENT DEDENT DEDENT def isEconomical ( n ) : NEW_LINE INDENT if ( n == 1 ) : NEW_LINE INDENT return False NEW_LINE DEDENT original_no = n NEW_LINE sumDigits = 0 NEW_LINE while ( original_no > 0 ) : NEW_LINE INDENT sumDigits += 1 NEW_LINE original_no = original_no // 10 NEW_LINE DEDENT pDigit = 0 NEW_LINE count_exp = 0 NEW_LINE i = 0 NEW_LINE p = 0 NEW_LINE while ( primes [ i ] <= n // 2 ) : NEW_LINE INDENT while ( n % primes [ i ] == 0 ) : NEW_LINE INDENT p = primes [ i ] NEW_LINE n = n // p NEW_LINE count_exp += 1 NEW_LINE DEDENT i += 1 NEW_LINE while ( p > 0 ) : NEW_LINE INDENT pDigit += 1 NEW_LINE p = p // 10 NEW_LINE DEDENT while ( count_exp > 1 ) : NEW_LINE INDENT pDigit += 1 NEW_LINE count_exp = count_exp // 10 NEW_LINE DEDENT DEDENT if ( n != 1 ) : NEW_LINE INDENT while ( n > 0 ) : NEW_LINE INDENT pDigit += 1 NEW_LINE n = n // 10 NEW_LINE DEDENT DEDENT if ( pDigit < sumDigits ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT sieveSundaram ( ) NEW_LINE for i in range ( 1 , 200 ) : NEW_LINE INDENT if ( isEconomical ( i ) ) : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE DEDENT DEDENT
Check if all objects of type A and B can be placed on N shelves | Function to return if allocation is possible or not ; Stores the shelves needed for items of type - A and type - B ; Find number of shelves needed for items of type - A ; Fill A / K shelves fully by the items of type - A ; Otherwise ; Fill A / L shelves fully and add remaining to an extra shelf ; Find number of shelves needed for items of type - B ; Fill B / L shelves fully by the items of type - B ; Fill B / L shelves fully and add remaining to an an extra shelf ; Total shelves needed ; If required shelves exceed N ; Driver Code
def isPossible ( A , B , N , K , L ) : NEW_LINE INDENT needa = 0 NEW_LINE needb = 0 NEW_LINE if ( A % K == 0 ) : NEW_LINE INDENT needa = A // K ; NEW_LINE DEDENT else : NEW_LINE INDENT needa = A // K + 1 NEW_LINE DEDENT if ( B % L == 0 ) : NEW_LINE INDENT needb = B // L NEW_LINE DEDENT else : NEW_LINE INDENT needb = B // L + 1 NEW_LINE DEDENT total = needa + needb NEW_LINE if ( total > N ) : NEW_LINE INDENT return False NEW_LINE DEDENT else : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT A , B , N = 3 , 3 , 3 NEW_LINE K , M = 4 , 2 NEW_LINE if ( isPossible ( A , B , N , K , M ) ) : NEW_LINE INDENT print ( ' YES ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' NO ' ) NEW_LINE DEDENT DEDENT
Minimise N such that sum of count of all factors upto N is greater than or equal to X | Python3 program for the above approach ; Array to store smallest prime factors of each no . ; Function to calculate smallest prime factor of N . ; Marking spf [ j ] if it is not previously marked ; Array to store the count of factor for N ; Prefix array which contains the count of factors from 1 to N ; Function to count total factors from 1 to N ; Store total factors of i ; Stores total factors from 1 to i ; Function to search lowest X such that the given condition is satisfied ; Find mid ; Search in the right half ; Search in the left half ; Return the position after Binary Search ; Function to find the required sum ; Precompute smallest prime factor of each value ; Calculate count of total factors from 1 to N ; Binary search to find minimum N ; Driver code ; Given Sum ; Function Call
MAX = 1000050 NEW_LINE spf = [ 0 for i in range ( MAX + 1 ) ] NEW_LINE def calculate_SPF ( ) : NEW_LINE INDENT for i in range ( MAX + 1 ) : NEW_LINE INDENT spf [ i ] = i ; NEW_LINE DEDENT for i in range ( 4 , MAX + 1 , 2 ) : NEW_LINE INDENT spf [ i ] = 2 ; NEW_LINE DEDENT i = 3 NEW_LINE while ( i * i <= MAX ) : NEW_LINE INDENT if ( spf [ i ] == i ) NEW_LINE INDENT j = i * i NEW_LINE while ( j <= MAX ) : NEW_LINE INDENT if ( spf [ j ] == j ) : NEW_LINE INDENT spf [ j ] = i ; NEW_LINE DEDENT j += i NEW_LINE DEDENT DEDENT i += 1 NEW_LINE DEDENT DEDENT tfactor = [ 0 for i in range ( MAX + 1 ) ] NEW_LINE pre = [ 0 for i in range ( MAX + 1 ) ] NEW_LINE def CountTotalfactors ( ) : NEW_LINE INDENT tfactor [ 1 ] = pre [ 1 ] = 1 ; NEW_LINE for i in range ( 2 , MAX + 1 ) : NEW_LINE INDENT mspf = spf [ i ] ; NEW_LINE prim = mspf ; NEW_LINE temp = i ; NEW_LINE cnt = 0 ; NEW_LINE while ( temp % mspf == 0 ) : NEW_LINE INDENT temp //= mspf ; NEW_LINE cnt += 1 ; NEW_LINE prim = prim * mspf ; NEW_LINE DEDENT tfactor [ i ] = ( cnt + 1 ) * NEW_LINE INDENT tfactor [ temp ] ; NEW_LINE DEDENT pre [ i ] = pre [ i - 1 ] + NEW_LINE INDENT tfactor [ i ] ; NEW_LINE DEDENT DEDENT DEDENT def BinarySearch ( X ) : NEW_LINE INDENT start = 1 ; NEW_LINE end = MAX - 1 ; NEW_LINE while ( start < end ) : NEW_LINE INDENT mid = ( start + end ) // 2 ; NEW_LINE if ( pre [ mid ] == X ) : NEW_LINE INDENT return mid ; NEW_LINE DEDENT elif ( pre [ mid ] < X ) : NEW_LINE INDENT start = mid + 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT end = mid ; NEW_LINE DEDENT DEDENT return start ; NEW_LINE DEDENT def findSumOfCount ( X ) : NEW_LINE INDENT calculate_SPF ( ) ; NEW_LINE CountTotalfactors ( ) ; NEW_LINE print ( BinarySearch ( X ) ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT X = 10 ; NEW_LINE findSumOfCount ( X ) ; NEW_LINE DEDENT
Check if the Matrix follows the given constraints or not | Stores true at prime indices ; Function to generate the prime numbers using Sieve of Eratosthenes ; If p is still true ; Mark all multiples of p ; Function returns sum of all elements of matrix ; Function to check if for all prime ( i + j ) , a [ i ] [ j ] is prime ; If index is prime ; Driver code ; Check for both conditions
prime = [ ] NEW_LINE def buildSieve ( sum ) : NEW_LINE INDENT global prime NEW_LINE prime = [ True for i in range ( sum + 1 ) ] NEW_LINE prime [ 0 ] = False NEW_LINE prime [ 1 ] = False NEW_LINE p = 2 NEW_LINE while ( p * p < ( sum + 1 ) ) : NEW_LINE INDENT if ( prime [ p ] ) : NEW_LINE INDENT for i in range ( p * 2 , sum + 1 , p ) : NEW_LINE INDENT prime [ i ] = False NEW_LINE DEDENT DEDENT p += 1 NEW_LINE DEDENT DEDENT def getSum ( a ) : NEW_LINE INDENT s = 0 NEW_LINE for i in range ( 4 ) : NEW_LINE INDENT for j in range ( 5 ) : NEW_LINE INDENT s += a [ i ] [ j ] NEW_LINE DEDENT DEDENT return s NEW_LINE DEDENT def checkIndex ( n , m , a ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT for j in range ( m ) : NEW_LINE INDENT if ( prime [ i + j ] and not prime [ a [ i ] [ j ] ] ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT DEDENT return True NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 4 NEW_LINE m = 5 NEW_LINE a = [ [ 1 , 2 , 3 , 2 , 2 ] , [ 2 , 2 , 7 , 7 , 7 ] , [ 7 , 7 , 21 , 7 , 10 ] , [ 2 , 2 , 3 , 6 , 7 ] ] NEW_LINE sum = getSum ( a ) NEW_LINE buildSieve ( sum ) NEW_LINE if ( prime [ sum ] and checkIndex ( n , m , a ) ) : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT DEDENT
How to calculate the Easter date for a given year using Gauss ' Algorithm | Python3 program for the above approach ; Function calculates and prints easter date for given year Y ; All calculations done on the basis of Gauss Easter Algorithm ; A corner case , when D is 29 ; Another corner case , when D is 28 ; If days > 31 , move to April April = 4 th Month ; Otherwise , stay on March March = 3 rd Month ; Driver Code
import math NEW_LINE def gaussEaster ( Y ) : NEW_LINE INDENT A = Y % 19 NEW_LINE B = Y % 4 NEW_LINE C = Y % 7 NEW_LINE P = math . floor ( Y / 100 ) NEW_LINE Q = math . floor ( ( 13 + 8 * P ) / 25 ) NEW_LINE M = ( 15 - Q + P - P // 4 ) % 30 NEW_LINE N = ( 4 + P - P // 4 ) % 7 NEW_LINE D = ( 19 * A + M ) % 30 NEW_LINE E = ( 2 * B + 4 * C + 6 * D + N ) % 7 NEW_LINE days = ( 22 + D + E ) NEW_LINE if ( ( D == 29 ) and ( E == 6 ) ) : NEW_LINE INDENT print ( Y , " - 04-19" ) NEW_LINE return NEW_LINE DEDENT elif ( ( D == 28 ) and ( E == 6 ) ) : NEW_LINE INDENT print ( Y , " - 04-18" ) NEW_LINE return NEW_LINE DEDENT else : NEW_LINE INDENT if ( days > 31 ) : NEW_LINE INDENT print ( Y , " - 04 - " , ( days - 31 ) ) NEW_LINE return NEW_LINE DEDENT else : NEW_LINE INDENT print ( Y , " - 03 - " , days ) NEW_LINE return NEW_LINE DEDENT DEDENT DEDENT Y = 2020 NEW_LINE gaussEaster ( Y ) NEW_LINE
Min steps to convert N | Python3 program for the above problem ; Adjacency list for numbers till 100001 ; Visited array ; To store distance of every vertex from A ; Function to check if number is a prime ; Function to check if numbers differ by only a single - digit ; Check the last digit of both numbers and increase count if different ; Generate all N digit primes ; For every prime number i check if an edge can be made . ; For every prime number i check if an edge can be made from i to j . ; If edge is possible then insert in the adjacency list ; Function to count distance ; If unvisited push onto queue and mark visited as 1 and add the distance of curr + 1. ; Driver code ; Call bfs traversal with root as node A ; Indicates not possible
mod = 1000000007 NEW_LINE lis = [ [ ] for i in range ( 100001 ) ] NEW_LINE primes = [ ] NEW_LINE vis = [ 0 for i in range ( 100001 ) ] NEW_LINE dis = [ 0 for i in range ( 100001 ) ] NEW_LINE def isPrime ( n ) : NEW_LINE INDENT i = 2 NEW_LINE while ( i * i <= n ) : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT i += 1 NEW_LINE DEDENT return True NEW_LINE DEDENT def valid ( a , b ) : NEW_LINE INDENT c = 0 NEW_LINE while ( a ) : NEW_LINE INDENT if ( ( a % 10 ) != ( b % 10 ) ) : NEW_LINE INDENT c += 1 NEW_LINE DEDENT a = int ( a / 10 ) NEW_LINE b = int ( b / 10 ) NEW_LINE DEDENT if ( c == 1 ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT def makePrimes ( N ) : NEW_LINE INDENT global primes NEW_LINE global lis NEW_LINE i = 0 NEW_LINE j = 0 NEW_LINE L = pow ( 10 , N - 1 ) NEW_LINE R = pow ( 10 , N ) - 1 NEW_LINE for i in range ( L , R + 1 ) : NEW_LINE INDENT if ( isPrime ( i ) ) : NEW_LINE INDENT primes . append ( i ) NEW_LINE DEDENT DEDENT for i in range ( len ( primes ) ) : NEW_LINE INDENT for j in range ( i + 1 , len ( primes ) ) : NEW_LINE INDENT a = primes [ i ] NEW_LINE b = primes [ j ] NEW_LINE if ( valid ( a , b ) ) : NEW_LINE INDENT lis [ a ] . append ( b ) NEW_LINE lis [ b ] . append ( a ) NEW_LINE DEDENT DEDENT DEDENT DEDENT def bfs ( src ) : NEW_LINE INDENT global vis NEW_LINE global dis NEW_LINE q = [ ] NEW_LINE q . append ( src ) NEW_LINE vis [ src ] = 1 NEW_LINE dis [ src ] = 0 NEW_LINE while ( len ( q ) != 0 ) : NEW_LINE INDENT curr = q [ 0 ] NEW_LINE q . pop ( 0 ) NEW_LINE for x in lis [ curr ] : NEW_LINE INDENT if ( vis [ x ] == 0 ) : NEW_LINE INDENT vis [ x ] = 1 NEW_LINE q . append ( x ) NEW_LINE dis [ x ] = dis [ curr ] + 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT N = 4 NEW_LINE makePrimes ( N ) NEW_LINE A = 1033 NEW_LINE B = 8179 NEW_LINE bfs ( A ) NEW_LINE if ( dis [ B ] == - 1 ) : NEW_LINE INDENT print ( - 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( dis [ B ] ) NEW_LINE DEDENT
Place Value of a given digit in a number | Function to find place value ; Digit , which we want to find place value . ; Number from where we want to find place value .
def placeValue ( N , num ) : NEW_LINE INDENT total = 1 NEW_LINE value = 0 NEW_LINE rem = 0 NEW_LINE while ( True ) : NEW_LINE INDENT rem = N % 10 NEW_LINE N = N // 10 NEW_LINE if ( rem == num ) : NEW_LINE INDENT value = total * rem NEW_LINE break NEW_LINE DEDENT total = total * 10 NEW_LINE DEDENT return value NEW_LINE DEDENT D = 5 NEW_LINE N = 85932 NEW_LINE print ( placeValue ( N , D ) ) NEW_LINE