Topic:
Orchard has a bunch of apples, a total of n head (n greater than 1 less than 9) bears points, the first small east, it divided the apples into n parts, one more, it threw away this one, took one of their apples, and then the second bear repeated the process, that is, to divide the n parts, throw one and then take a copy, And so on until the end of the bear is like this (the last bear can take away after the 0, but also a n share). Ask at least how many of these apples were at the beginning.
Given an integer n, represents the number of bears, returning the original number of apples. Guaranteed to have a solution.
Test examples:
2
Return:
3
defone_pear_operation (M, I, N): # # # I+1 The number of apples before the bear split apples
# # # of apples before the first bear divided apples
# # # N is the total number of bears P=float (m*n)/(n-1) +1T=float (p-1)/Nif( notT.is_integer ()) andI>0: # # # Every bear should take a whole number of apples, and only the last bear is allowed to take away 0 apples and throw away an apple, the remaining 0 applesreturn1.1Else: returnPdefprocessing (n, p):
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # from the last bear, if the last bear does not match the number of apples before the Apple is 1=P Flag=1 forIinchRange (n-1): S=one_pear_operation (s,i,n)if notS.is_integer (): Flag=0 Break returns, FlagdefMain (N):
# # # At least 1 apples before the last bear split apples p=1.0 while(True): s=p S, Flag=processing (n,s)ifFlag==1 andS>2: PrintInt (s) Break Else: while(True): P+=1Temp=float (p-1)/NifTemp.is_integer (): Break if __name__=='__main__': #processing (6,1)Main (3) #Print S
Question 2---apple