Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Determine the number of positive integers x, where x is
- #less than equal to 9,999,999 and the sum of the digits in x is 31.
- a=0
- b=0
- c=0
- d=0
- e=0
- f=0
- g=0
- solution=0
- while 1000000*a+100000*b+10000*c+1000*d+100*e+10*f+g<=9999999:
- if a+b+c+d+e+f+g==31:
- solution+=1
- if g<9:
- g+=1
- else:
- if f<9:
- f+=1
- else:
- f=0
- if e<9:
- e+=1
- else:
- e=0
- if d<9:
- d+=1
- else:
- d=0
- if c<9:
- c+=1
- else:
- c=0
- if b<9:
- b+=1
- else:
- b=0
- if a<9:
- a+=1
- print(solution)
Advertisement
Add Comment
Please, Sign In to add comment