![見出し画像](https://assets.st-note.com/production/uploads/images/159543796/rectangle_large_type_2_2d3e9d1bcee79449ea45762c28262072.png?width=1200)
遅延評価を使う
競プロ典型 90 問 25 日目 - Digit Product Equation(★7)
main = interact $ show . sol . map (read @Int) . words
sol (n:b:_)
| n<b = 0
| otherwise = length s + if f b==0 then 1 else 0
where
g p = takeWhile (<=n-b) . iterate (* p)
s = g 2 1 >>= g 3 >>= g 5 >>= g 7 >>= \p ->
if f (p+b)==p then return p else []
f m = case quotRem m 10 of
(_,0) -> 0
(0,r) -> r
(q,1) -> f q
(q,r) -> r*f q
いいなと思ったら応援しよう!
![karoyakani](https://assets.st-note.com/production/uploads/images/153060341/profile_9698d87ebc4a2db16c1de3967836ae3d.jpg?width=600&crop=1:1,smart)