Skip to content

Instantly share code, notes, and snippets.

@willf
Created November 10, 2017 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willf/f4670c736afc579d1d0149714ea91af6 to your computer and use it in GitHub Desktop.
Save willf/f4670c736afc579d1d0149714ea91af6 to your computer and use it in GitHub Desktop.
from itertools import chain
from sympy.ntheory import factorint
def strp(n,p):
if p == 1:
return str(n)
return str(n) + "^" + str(p)
def strf(f):
return "*".join([strp(k, f[k]) for k in sorted(f.keys())])
def ok_factor(f, n):
if not all([x in ['1', '3', '7'] for x in list(str(f))]):
return False
if not all([x in ['1', '3', '7'] for x in list(str(n))]):
return False
return True
def f(x):
fs = factorint(x)
if len(fs) > 1 and all([ok_factor(i, fs[i]) for i in fs]):
print(x, strf(fs))
# for x in range(1000,10000):
# f(x)
#
# 1001 7*11*13
# 1011 3*337
# 1023 3*11*31
# 1029 3*7^3
# 1119 3*373
# 1147 31*37
# 1207 17*71
# 1209 3*13*31
# 1211 7*173
# 1221 3*11*37
# 1241 17*73
# 1243 11*113
# 1309 7*11*17
# 1441 11*131
# 1443 3*13*37
# 1469 13*113
# 1491 3*7*71
# 1507 11*137
# 1533 3*7*73
# 1547 7*13*17
# 1581 3*17*31
# 1703 13*131
# 1781 13*137
# 1887 3*17*37
# 1903 11*173
# 1917 3^3*71
# 1921 17*113
# 1971 3^3*73
# 2079 3^3*7*11
# 2177 7*311
# 2191 7*313
# 2199 3*733
# 2201 31*71
# 2219 7*317
# 2227 17*131
# 2249 13*173
# 2263 31*73
# 2317 7*331
# 2319 3*773
# 2329 17*137
# 2343 3*11*71
# 2359 7*337
# 2373 3*7*113
# 2387 7*11*31
# 2409 3*11*73
# 2431 11*13*17
# 2457 3^3*7*13
# 2611 7*373
# 2627 37*71
# 2701 37*73
# 2751 3*7*131
# 2769 3*13*71
# 2821 7*13*31
# 2847 3*13*73
# 2849 7*11*37
# 2877 3*7*137
# 2941 17*173
# 3003 3*7*11*13
# 3051 3^3*113
# 3213 3^3*7*17
# 3351 3*1117
# 3367 7*13*37
# 3421 11*311
# 3441 3*31*37
# 3443 11*313
# 3487 11*317
# 3503 31*113
# 3513 3*1171
# 3537 3^3*131
# 3621 3*17*71
# 3633 3*7*173
# 3641 11*331
# 3689 7*17*31
# 3699 3^3*137
# 3707 11*337
# 3723 3*17*73
# 3729 3*11*113
# 3773 7^3*11
# 3861 3^3*11*13
# 3927 3*7*11*17
# 3993 3*11^3
# 4043 13*311
# 4061 31*131
# 4069 13*313
# 4103 11*373
# 4119 3*1373
# 4121 13*317
# 4181 37*113
# 4247 31*137
# 4303 13*331
# 4323 3*11*131
# 4381 13*337
# 4403 7*17*37
# 4407 3*13*113
# 4433 11*13*31
# 4459 7^3*13
# 4521 3*11*137
# 4641 3*7*13*17
# 4671 3^3*173
# 4847 37*131
# 4849 13*373
# 5049 3^3*11*17
# 5069 37*137
# 5109 3*13*131
# 5131 7*733
# 5183 71*73
# 5199 3*1733
# 5287 17*311
# 5291 11*13*37
# 5321 17*313
# 5331 3*1777
# 5343 3*13*137
# 5363 31*173
# 5389 17*317
# 5411 7*773
# 5467 7*11*71
# 5621 7*11*73
# 5627 17*331
# 5709 3*11*173
# 5729 17*337
# 5763 3*17*113
# 5797 11*17*31
# 5831 7^3*17
# 5859 3^3*7*31
# 5967 3^3*13*17
# 6341 17*373
# 6401 37*173
# 6461 7*13*71
# 6531 3*7*311
# 6573 3*7*313
# 6591 3*13^3
# 6603 3*31*71
# 6643 7*13*73
# 6657 3*7*317
# 6681 3*17*131
# 6747 3*13*173
# 6789 3*31*73
# 6851 13*17*31
# 6919 11*17*37
# 6951 3*7*331
# 6987 3*17*137
# 6993 3^3*7*37
# 7077 3*7*337
# 7161 3*7*11*31
# 7293 3*11*13*17
# 7819 7*1117
# 7833 3*7*373
# 7881 3*37*71
# 8023 71*113
# 8029 7*31*37
# 8063 11*733
# 8103 3*37*73
# 8177 13*17*37
# 8197 7*1171
# 8249 73*113
# 8397 3^3*311
# 8449 7*17*71
# 8451 3^3*313
# 8463 3*7*13*31
# 8503 11*773
# 8547 3*7*11*37
# 8559 3^3*317
# 8687 7*17*73
# 8701 7*11*113
# 8823 3*17*173
# 8937 3^3*331
# 9099 3^3*337
# 9207 3^3*11*31
# 9261 3^3*7^3
# 9301 71*131
# 9317 7*11^3
# 9411 3*3137
# 9529 13*733
# 9563 73*131
# 9611 7*1373
# 9641 31*311
# 9703 31*313
# 9727 71*137
# 9827 31*317
# 9939 3*3313
# 9993 3*3331
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment