Largest odd divisor Game to check which player wins | Python3 implementation to find the Largest Odd Divisor Game to check which player wins ; Function to find the Largest Odd Divisor Game to check which player wins ; Check if n == 1 then player 2 will win ; Check if n == 2 or n is odd ; While n is greater than k and divisible by 2 keep incrementing tha val ; Loop to find greatest odd divisor ; Check if n is a power of 2 ; Check if cnt is not one then player 1 wins ; Driver code
import math NEW_LINE def findWinner ( n , k ) : NEW_LINE INDENT cnt = 0 ; NEW_LINE if ( n == 1 ) : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT elif ( ( n & 1 ) or n == 2 ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT tmp = n ; NEW_LINE val = 1 ; NEW_LINE while ( tmp > k and tmp % 2 == 0 ) : NEW_LINE INDENT tmp //= 2 ; NEW_LINE val *= 2 ; NEW_LINE DEDENT for i in range ( 3 , int ( math . sqrt ( tmp ) ) + 1 ) : NEW_LINE INDENT while ( tmp % i == 0 ) : NEW_LINE INDENT cnt += 1 ; NEW_LINE tmp //= i ; NEW_LINE DEDENT DEDENT if ( tmp > 1 ) : NEW_LINE INDENT cnt += 1 ; NEW_LINE DEDENT if ( val == n ) : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT elif ( n / tmp == 2 and cnt == 1 ) : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 1 ; k = 1 ; NEW_LINE findWinner ( n , k ) ; NEW_LINE DEDENT