Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- f←{({+/⍵=⍵∧⍳⍵}¨⍳2*⍵)⍳⍵}
- > f 13
- 4096
- > f 14
- 192
- {.{.,{)1$%},,-=}+2@?,?}:f;
- {.{)..,{)1$%},,-@=!}+do}:f;
- 13 f p # => 4096
- 14 f p # => 192
- 15 f p # => 144
- # Calculate numbers of divisors
- # .,{)1$%},,-
- # Input stack: n
- # After application: D(n)
- ., # push array [0 .. n-1] to stack
- { # filter array by function
- ) # take array element and increase by one
- 1$% # test division of n ($1) by this value
- }, # -> List of numbers x where n is NOT divisible by x+1
- , # count these numbers. Stack now is n xd(n)
- - # subtracting from n yields the result
- # Test if number of divisors D(n) is equal to d
- # {D=}+ , for D see above
- # Input stack: n d
- # After application: D(n)==d
- {
- # swap stack -> d n
- D # calculate D(n) -> d D(n)
- = # compare
- }+ # consumes d from stack and prepends it to code block
- # Search for the first number which D(n) is equal to d
- # .T2@?,? , for T see above
- # Input stack: d
- # After application: f(d)
- . # duplicate -> d d
- T # push code block (!) for T(n,d) -> d T(n,d)
- 2@? # swap and calculate 2^d -> T(n,d) 2^d
- , # make array -> T(n,d) [0 .. 2^d-1]
- ? # search first element in array where T(n,d) is true -> f(d)
- f=lambda n,k=1:n==sum(k%i<1for i in range(1,k+1))and k or f(n,k+1)
- def f(n,k=1):
- while 1:
- if sum(k%i<1for i in range(1,k+1))==n:return k
- k+=1
- (For[i=1,DivisorSum[++i,1&]!=#,];i)&
- (For[i=1,DivisorSum[++i,1&]!=#,];i)&@200
- 498960
- f=.>:@]^:([~:[:*/[:>:_&q:@])^:_&1
- f 19
- 262144
- f k=head[x|x<-[k..],length[y|y<-[1..x],mod x y==0]==k]
- {{$[x=+/a=_a:y%!1+y;y;.z.s[x;1+y]]}[x;0]}
- k){{$[x=+/a=_a:y%!1+y;y;.z.s[x;1+y]]}[x;0]}14
- 192
- k){{$[x=+/a=_a:y%!1+y;y;.z.s[x;1+y]]}[x;0]}13
- 'stack
- F n
- i←0
- l:i←i+1
- →(n≠+/0=(⍳i)|i)/l
- i
- F 6
- 12
- {⍵{⍺=+/0=⍵|⍨⍳⍵:⍵⋄⍺∇⍵+1}1}
- f=function(N){n=1;while(N-sum(!n%%1:n))n=n+1;n}
- f(6)
- [1] 12
- f(13)
- [1] 4096
- function f(N){for(j=i=m=1;m-N||j-i;j>i?i+=m=j=1:m+=!(i%++j));return i}
- for(j=i=m=1;m-N||j-i;j>i?i+=m=j=1:m+=!(i%++j))
- f n=until(i->n==sum[1|j<-[1..i],rem i j<1])(+1)1
- i;f(n){while(n-g(++i));return i;}g(j){return j?!(i%j)+g(j-1):0;}
- i;j;k;f(n){while(k-n&&++i)for(k=0,j=1;j<=i;k+=!(i%j++));return i;}
- 1<>p=[]
- x<>p|mod x p>0=x<>(p+1)|1<2=(div x p<>p)++[p]
- f k=product[p^(c-1)|(p,c)<-zip[r|r<-[2..k],2>length(r<>2)](k<>2)]
- main=do putStrLn$show$ f (100000::Integer)
- *Main> f 18
- 180
- *Main> f 10000000
- 1740652905587144828469399739530000
- *Main> f 1000000000
- 1302303070391975081724526582139502123033432810000
- *Main> f 100000000000
- 25958180173643524088357042948368704203923121762667635047013610000
- *Main> f 10000000000000
- 6558313786906640112489895663139340360110815128467528032775795115280724604138270000
- *Main> f 1000000000000000
- 7348810968806203597063900192838925279090695601493714327649576583670128003853133061160889908724790000
- *Main> f 100000000000000000
- 71188706857499485011467278407770542735616855123676504522039680180114830719677927305683781590828722891087523475746870000
- *Main> f 10000000000000000000
- 2798178979166951451842528148175504903754628434958803670791683781551387366333345375422961774196997331643554372758635346791935929536819490000
- *Main> f 10000000000000000000000
- 6628041919424064609742258499702994184911680129293140595567200404379028498804621325505764043845346230598649786731543414049417584746693323667614171464476224652223383190000
- f(n,s){return--s?f(n,s)+!(n%s):1;}
- x;
- g(d){return++x,f(x,x)-d&&g(d),x;}
- (For[k=1,DivisorSigma[0, k]!= #,k++]; k)&
- (For[k = 1, DivisorSigma[0, k] != #, k++]; k) &[7]
- (* 64 *)
- smallestNumber[nDivisors_] :=
- Module[{k = 1},
- While[Length[Divisors[k]] != nDivisors, k++];k]
- Table[{i, nDivisors[i]}, {i, 1, 20}] // Grid
- 2*RÆdi
- 2*RÆdi Main link. Argument: n (integer)
- 2* Compute 2**n.
- R Range; yield [1, ..., 2**n]. Note that 2**(n-1) has n divisors, so this
- range contains the number we are searching for.
- Æd Divisor count; compute the number of divisors of each integer in the range.
- i Index; return the first (1-based) index of n.
- int a(int d){int k=0,r,i;for(;r!=d;k++)for(i=2,r=1;i<=k;i++)if(!(k%i))r++;return k-1;}
- from itertools import*
- f=lambda n:next(i for i in count()if sum(1>i%(j+1)for j in range(i))==n)
- fl
- f The list of factors of
- the input variable
- l has length equal to
- the output variable.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement