• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Aug 26th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import Data.List
2. import Data.Maybe
3. import qualified Data.List.NonEmpty as NonEmpty
4.
5. firstState = 2
6. nextNumber state
7.   | state==2 = state+1
8.   | otherwise = state+2
9.
10. curNumber state=state
11. stopFlag state number = state*state>number
12.
13. prime_factor n = map (\x->(NonEmpty.head x,length x)) . NonEmpty.group  \$ prime_factor' firstState curNumber nextNumber stopFlag n
14.
15. prime_factor'::s->(s->Int)->(s->s)->(s->Int->Bool)->Int->[Int]
16. prime_factor' startState curValue nextState stopFlag n
17.   | n `mod` curNumber ==0 = [curNumber] ++ (prime_factor' startState curValue nextState stopFlag (n `div` curNumber))
18.   | stopFlag startState n = [n]
19.   | otherwise = prime_factor' (nextState startState) curValue nextState stopFlag n
20.   where curNumber = curValue startState
21.
22. -- все возможные первые числа в разложении (числа представлены в виде показателей степеней соответствующих простых чисел)
23. get_seq  = traverse (\x->[0..x])
24.
25. -- все разложение перебираются без повторений
26. divisors n 1 = [[n]]
27. divisors n m = [[x]++y|x <- get_seq n,y<-divisors ((zipWith (-)) n x) (m-1),x<=head y]
28.
29. powerlist n m = product \$ zipWith (^) n m
30.
31. -- разбиение на множители числа n на m множителей
32. factor n m =  map (map (powerlist primes )) (divisors powers m)
33.    where factors = prime_factor n
34.          (primes,powers)  = unzip factors
35.
36. exper n m = find (\x -> (length x)>1) \$ NonEmpty.groupAllWith sum (factor n m)
37.
38. exper_big n m = filter ( all (all (/=1) ) ) \$ catMaybes [exper x m | x<-[2..n]]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top