forked from Tecmax/JavaAndroidPractise
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp130.hs
More file actions
22 lines (18 loc) · 647 Bytes
/
Copy pathp130.hs
File metadata and controls
22 lines (18 loc) · 647 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{-
- Solution to Project Euler problem 130
- Copyright (c) Project Nayuki. All rights reserved.
-
- https://www.nayuki.io/page/project-euler-solutions
- https://github.com/nayuki/Project-Euler-solutions
-}
import qualified EulerLib
main = putStrLn (show ans)
cond i = (mod i 5 /= 0) && (not (EulerLib.isPrime i)) && mod (i - 1) (findLeastDivisibleRepunit i) == 0
ans = sum (take 25 (filter cond [7,9..]))
findLeastDivisibleRepunit :: Integer -> Integer
findLeastDivisibleRepunit n = if (mod n 2) == 0 || (mod n 5) == 0
then 0
else let
func 0 _ k = k
func s p k = func (mod (s + p * 10) n) (mod (p * 10) n) (k + 1)
in func 1 1 1