Question 2---apple

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.