#-*-coding:utf8;-*- #qpy:console import heapq def is_palindrome(n): return ''.join(reversed(str(n))) == str(n) pile = [(-979*999,979,999)] visited = set() while pile: x, a, b = heapq.heappop(pile) if (a,b) in visited: continue if is_palindrome(-x): print(f"FOUND {-x} = {a} * {b}") print(len(visited)) break print(-x,a,b) visited.add((a,b)) heapq.heappush(pile, (-(a-11)*b, a-11, b)) heapq.heappush(pile, (-a*(b-1), a, b-1))
Standard input is empty
978021 979 999 977042 979 998 976063 979 997 975084 979 996 974105 979 995 973126 979 994 972147 979 993 971168 979 992 970189 979 991 969210 979 990 968231 979 989 967252 979 988 967032 968 999 966273 979 987 966064 968 998 965294 979 986 965096 968 997 964315 979 985 964128 968 996 963336 979 984 963160 968 995 962357 979 983 962192 968 994 961378 979 982 961224 968 993 960399 979 981 960256 968 992 959420 979 980 959288 968 991 958441 979 979 958320 968 990 957462 979 978 957352 968 989 956483 979 977 956384 968 988 956043 957 999 955504 979 976 955416 968 987 955086 957 998 954525 979 975 954448 968 986 954129 957 997 953546 979 974 953480 968 985 953172 957 996 952567 979 973 952512 968 984 952215 957 995 951588 979 972 951544 968 983 951258 957 994 950609 979 971 950576 968 982 950301 957 993 949630 979 970 949608 968 981 949344 957 992 948651 979 969 948640 968 980 948387 957 991 947672 968 979 947672 979 968 947430 957 990 946704 968 978 946693 979 967 946473 957 989 945736 968 977 945714 979 966 945516 957 988 945054 946 999 944768 968 976 944735 979 965 944559 957 987 944108 946 998 943800 968 975 943756 979 964 943602 957 986 943162 946 997 942832 968 974 942777 979 963 942645 957 985 942216 946 996 941864 968 973 941798 979 962 941688 957 984 941270 946 995 940896 968 972 940819 979 961 940731 957 983 940324 946 994 939928 968 971 939840 979 960 939774 957 982 939378 946 993 938960 968 970 938861 979 959 938817 957 981 938432 946 992 937992 968 969 937882 979 958 937860 957 980 937486 946 991 937024 968 968 936903 957 979 936903 979 957 936540 946 990 936056 968 967 935946 957 978 935924 979 956 935594 946 989 935088 968 966 934989 957 977 934945 979 955 934648 946 988 934120 968 965 934065 935 999 934032 957 976 933966 979 954 933702 946 987 933152 968 964 933130 935 998 933075 957 975 932987 979 953 932756 946 986 932195 935 997 932184 968 963 932118 957 974 932008 979 952 931810 946 985 931260 935 996 931216 968 962 931161 957 973 931029 979 951 930864 946 984 930325 935 995 930248 968 961 930204 957 972 930050 979 950 929918 946 983 929390 935 994 929280 968 960 929247 957 971 929071 979 949 928972 946 982 928455 935 993 928312 968 959 928290 957 970 928092 979 948 928026 946 981 927520 935 992 927344 968 958 927333 957 969 927113 979 947 927080 946 980 926585 935 991 926376 957 968 926376 968 957 926134 946 979 926134 979 946 925650 935 990 925419 957 967 925408 968 956 925188 946 978 925155 979 945 924715 935 989 924462 957 966 924440 968 955 924242 946 977 924176 979 944 923780 935 988 923505 957 965 923472 968 954 923296 946 976 923197 979 943 923076 924 999 922845 935 987 922548 957 964 922504 968 953 922350 946 975 922218 979 942 922152 924 998 921910 935 986 921591 957 963 921536 968 952 921404 946 974 921239 979 941 921228 924 997 920975 935 985 920634 957 962 920568 968 951 920458 946 973 920304 924 996 920260 979 940 920040 935 984 919677 957 961 919600 968 950 919512 946 972 919380 924 995 919281 979 939 919105 935 983 918720 957 960 918632 968 949 918566 946 971 918456 924 994 918302 979 938 918170 935 982 917763 957 959 917664 968 948 917620 946 970 917532 924 993 917323 979 937 917235 935 981 916806 957 958 916696 968 947 916674 946 969 916608 924 992 916344 979 936 916300 935 980 915849 957 957 915728 946 968 915728 968 946 915684 924 991 915365 935 979 915365 979 935 914892 957 956 914782 946 967 914760 924 990 914760 968 945 914430 935 978 914386 979 934 913935 957 955 913836 924 989 913836 946 966 913792 968 944 913495 935 977 913407 979 933 912978 957 954 912912 924 988 912890 946 965 912824 968 943 912560 935 976 912428 979 932 912087 913 999 912021 957 953 911988 924 987 911944 946 964 911856 968 942 911625 935 975 911449 979 931 911174 913 998 911064 924 986 911064 957 952 910998 946 963 910888 968 941 910690 935 974 910470 979 930 910261 913 997 910140 924 985 910107 957 951 910052 946 962 909920 968 940 909755 935 973 909491 979 929 909348 913 996 909216 924 984 909150 957 950 909106 946 961 908952 968 939 908820 935 972 908512 979 928 908435 913 995 908292 924 983 908193 957 949 908160 946 960 907984 968 938 907885 935 971 907533 979 927 907522 913 994 907368 924 982 907236 957 948 907214 946 959 907016 968 937 906950 935 970 FOUND 906609 = 913 * 993 283