#module
#deffunc swap var a, var b, local c
c=a
a=b
b=c
return
#defcfunc gcd int a, int b, local x, local y, local z
x=a
y=b
repeat
z=x\y
if z=0 : break
x=y
y=z
loop
return y
#deffunc fuga array ru, array rl, var rnum, local u, local l
rnum=0
repeat 9, 1
l=cnt
repeat l-1, 1
u=cnt
if gcd(u, l)!1 : continue
ru.rnum=u
rl.rnum=l
rnum++
loop
loop
return rnum
#defcfunc dec var x
if x<=0 : return 0
x--
return 1
#deffunc check int number, int used, var count, array ru, array rl, int rnum, \
local dcount_org, local dcount, local n, local u, local breaked
dim dcount_org, 10
dim dcount, 10
n=number
repeat used
dcount_org(n\10)++
n/=10
loop
repeat rnum
if number\rl.cnt : continue
memcpy dcount, dcount_org, 4*10
if dcount(ru.cnt) : continue
if dec(dcount(rl.cnt))=0 : continue
dcount(ru.cnt)++
u=ru.cnt*(number/rl.cnt)
breaked=0
repeat used
if dec(dcount(u\10))=0 {
breaked=1
break
}
u/=10
loop
if breaked : continue
logmes strf("%d / %d", ru.cnt*(number/rl.cnt), number)
count++
loop
return
#deffunc hoge int number, array digit, int used, var count, array ru, array rl, int rnum, \
local d
if used : check number, used, count, ru, rl, rnum
repeat 9-used
d=digit(cnt)
swap digit(cnt), digit(9-1-used)
hoge number*10+d, digit, used+1, count, ru, rl, rnum
swap digit(cnt), digit(9-1-used)
loop
await
return
#deffunc solve local count, local digit, local ru, local rl, local rnum
fuga ru, rl, rnum
repeat 9
digit.cnt=cnt+1
loop
hoge 0, digit, 0, count, ru, rl, rnum
return count
#global
solve
mes stat
; 14.4 sec
; 349
I21vZHVsZQojZGVmZnVuYyBzd2FwIHZhciBhLCB2YXIgYiwgbG9jYWwgYwoJYz1hCglhPWIKCWI9YwoJcmV0dXJuCgoKI2RlZmNmdW5jIGdjZCBpbnQgYSwgaW50IGIsIGxvY2FsIHgsIGxvY2FsIHksIGxvY2FsIHoKCXg9YQoJeT1iCglyZXBlYXQKCQl6PXhceQoJCWlmIHo9MCA6IGJyZWFrCgk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