Sichanov

sum & product

May 25th, 2021
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 KB | None | 0 0
  1. # n = int(input())
  2. # is_valid = False # True
  3. # for a in range(1, 10):
  4. #     for b in range(9, a - 1, -1):
  5. #         for c in range(0, 10):
  6. #             for d in range(9, c - 1, -1):
  7. #                 sum = a + b + c + d
  8. #                 product = a * b * c * d
  9. #                 if sum == product and n % 10 == 5:
  10. #                     is_valid = True
  11. #                     print(f'{a}{b}{c}{d}')
  12. #                     break
  13. #                 elif product // sum == 3 and n % 3 == 0:
  14. #                     is_valid = True
  15. #                     print(f'{d}{c}{b}{a}')
  16. #                     break
  17. #             if is_valid:
  18. #                 break
  19. #         if is_valid:
  20. #             break
  21. #     if is_valid:
  22. #         break
  23. # if not is_valid:
  24. #     print('Nothing found')
  25.  
  26. n = int(input())
  27. is_valid = False # True
  28. for a in range(1, 10):
  29.     for b in range(9, a - 1, -1):
  30.         for c in range(0, 10):
  31.             for d in range(9, c - 1, -1):
  32.                 sum = a + b + c + d
  33.                 product = a * b * c * d
  34.                 if sum == product and n % 10 == 5:
  35.                     is_valid = True
  36.                     print(f'{a}{b}{c}{d}')
  37.  
  38.                 elif product // sum == 3 and n % 3 == 0:
  39.                     is_valid = True
  40.                     print(f'{d}{c}{b}{a}')
  41.                 if is_valid:
  42.                     exit()
  43. if not is_valid:
  44.     print('Nothing found')
Advertisement
Add Comment
Please, Sign In to add comment