19

05AB1E, 2 bytes ÑO Try it online! How? Ñ Divisors O Sum


16

PowerShell v3+, 450 bytes param($n)function f{param($a)for($i=2;$a-gt1){if(!($a%$i)){$i;$a/=$i}else{$i++}}} $y=($x=@((f $n)-split'(.)'-ne''|sort))|?{$_-eq(f $_)} $a,$b=$x $a=,$a while($b){$z,$b=$b;$a=$a+($a+$y|%{$c="$_";0..$c.Length|%{-join($c[0..$_]+$z+$c[++$_..$c.Length])};"$z$c";"$c$z"})|select -u} $x=-join($x|sort -des) $l=@();$a|?{$_-eq(f $_)}|%{$j=$_;...


16

Brachylog, 4 bytes fk+? Try it online! The predicate succeeds for perfect inputs and fails for imperfect inputs, printing true. or false. if run as a complete program (except on the last test case which takes more than a minute on TIO). The input's f factors k without the last element + sum to ? the input.


15

Pyth, 1 byte P I like Pyth's chances in this challenge.


14

Python 2, 55 bytes f=lambda n,k=2:n/k*[0]and(f(n,k+1),[k]+f(n/k,k))[n%k<1] Try it online!


13

Husk, 35 31 30 29 26 25 24 22 20 19 15 bytes -7 bytes thanks to @Zgarb! Saved an extra 4 bytes, indirectly, thanks to Zgarb ḋhΣhgφṁȯ`Jḋ2⁰ṗp Try it online! Explaination φ -- Define a recursive function which calls itself ⁰ and is applied to an Integer ṁ p -- map then concatenate over its prime factors ṗ -- ...


12

Proof that every repunit has a novel prime factor Using Zsigmondy's Theorem, the proof is simple. From Wikipedia: In number theory, Zsigmondy's theorem, named after Karl Zsigmondy, states that if a > b > 0 are coprime integers, then for any integer n ≥ 1, there is a prime number p (called a primitive prime divisor) that divides an − bn and does not ...


11

SageMath, 31 Bytes N=input() print N,"=",factor(N) Test case: 83891573479027823458394579234582347590825792034579235923475902312344444 Outputs: 83891573479027823458394579234582347590825792034579235923475902312344444 = 2^2 * 3^2 * 89395597 * 98966790508447596609239 * 263396636003096040031295425789508274613


10

Julia, 95 93 bytes g(x)=reduce(vcat,map(p->map(sum,p),partitions([keys(factor(x))...]))) f(a,b)=g(a)∩g(b)!=[] The primary function is f and it calls a helper function g. Ungolfed: function g(x::Integer) # Find the sum of each combination of prime factors of the input return reduce(vcat, map(p -> map(sum, p), partitions([keys(factor(x))...]))...


10

Jelly, 12 bytes Æf*³<‘Ạ 1Ç#Ṫ Takes n and k (one-indexed) as command-line arguments. Try it online! How it works 1Ç#Ṫ Main link. Left argument: n. Right argument: k 1 Set the return value to 1. Ç# Execute the helper link above for r = 1, 2, 3, ... until k of them return a truthy value. Yield the list of all k matches. Ṫ ...


10

Python 2, 53 bytes f=lambda n,i=2:n/i*[f]and[f(n,i+1),[i]+f(n/i)][n%i<1] Tries each potential divisor i in turn. If i is a divisor, prepends it and restarts with n/i. Else, tries the next-highest divisor. Because divisors are checked in increasing order, only the prime ones are found. As a program, for 55 bytes: n=input();i=2 while~-n: if n%i:i+=1 ...


10

Python3, 49 47 bytes def f(x): l=x**.5//1 while x%l:l-=1 return l Explanation l=x**.5//1 → Assign l the largest integer less than equal to the square root of x while x%l:l-=1 → While l does not evenly divide x, decrement l. Edits Mention Python3, not Python2 Use ...//1 to save two bytes. (Decimals are okay! Thanks @Rod)


10

JavaScript (ES6),  45  44 bytes Takes input as (n)(p1), where \$n\$ is 0-indexed. n=>g=(p,d=2)=>n?~p%d?g(p,d+1):--n?g(p*d):d:p Try it online! Commented n => // n = 0-based index of the requested term g = ( // g is a recursive function taking: p, // p = current prime product d = 2 // d ...


9

Husk, 11 10 bytes Saved one byte thanks to Zgarb! Ωεo?oṗ←¬Ep Returns 1 for unique, 0 otherwise Try it online! Or returning the first 50 Explanation: Ωε Until the result is small (either 1 or 0), we repeat the following p Get the prime factors o? If ... E they are all equal: ȯṗ← Get the index ...


9

Neim, 3 bytes 𝐕𝐬𝔼 Try it online! (I don't actually know how to run all of the test cases at once, since I started learning Neim about fifteen minutes ago, but I did check them individually.) Prints 0 for imperfect, 1 for perfect. 𝐕 Pop an int from the stack and push its proper divisors, implicitly reading the int from a line of input as ...


9

05AB1E, 6 bytes This produces and infinite output stream. λλP>fW Try it online! (link includes a slightly modified version, λ£λP>fW, which instead outputs the first \$n\$ terms) Explanation Very straightforward. Given \$p_1\$ and \$n\$, the program does the following: Starts with \$p_1\$ as an initial parameter for the infinite stream (which is ...


8

Python - 104 97 95 92 try it n=input() s=i=2 c=1 while s<n: s*=i+c;c+=1 if s==n:print range(i,i+c) if s/n:i+=1;s,c=i,1 If n is, e.g., set to 120 beforehand, the program outputs the two solutions: [2, 3, 4, 5] [4, 5, 6]


8

Java - 124 String f(int t){int s=2,h=3,p=s,i;String o="";for(;p!=t&&s*s<t;p=p<t?p*h++:p/s++);if(p==t)for(i=s;i<h;o+++=i+" ");return o;} Starting at 2, this loops until the start number is > the square root of the target (or target is reached exactly). If the product is low, it multiplies by the high number and ...


8

CJam, 26 23 bytes {_mfs$:XW%i){mfs$X=},^} Try it online Explanation Concatenating two numbers always gives a bigger result than multiplying them. So the largest number we possibly need to consider is the largest number we can form from the digits of the input's prime factorisation, which is just all digits sorted in descending order. For the given ...


8

Mathematica, 38 30 bytes Thanks @MartinEnder for 8 bytes! Join@@Table@@@FactorInteger@#&


8

Jelly,  22 20  19 bytes -1 thanks to Erik the Outgolfer (tail zeros from both sides, t, rather than from the right œr) ÆfÆC$ÐLŒṘO%3ḟ2Ḋt0ṖḄ A monadic link taking an integer greater than 2 and returning an integer greater than 0 (2 would return 0 as per the original spec too). Try it online! How? This almost exactly replicates the description ...


8

05AB1E, 2 bytes ÓZ Try it online! How? Ó exponents of prime factors Z maximum


8

05AB1E, 13 bytes Encoder, 8 bytes 0ì¥ĀηOØP Try it online! Explanation 0ì # prepend 0 to input ¥ # calculate deltas Ā # truthify each η # calculate prefixes O # sum each Ø # get the prime at that index P # product Decoder, 5 bytes Ò.ØÉJ Try it online! Explanation Ò # get ...


8

MATL, 7 bytes Z\tn2/) Try it online! For this explanation, we will use '12' as a sample input. Explanation: Z\ % Divisors. % Stack: % [1 2 3 4 6 12] t % Duplicate. % Stack: % [1 2 3 4 6 12] % [1 2 3 4 6 12] n % Number of elements. % Stack: % 6 % [1 2 3 4 6 12] ...


8

R, 33 29 bytes !2*(n=scan())-(x=1:n)%*%!n%%x Try it online! Returns TRUE for perfect numbers and FALSE for imperfect ones.


8

JavaScript (ES6),  91 83 79  76 bytes f=(b,n=b,k=n)=>(g=d=>k<2?d<n:k%d?g(d+1):b*~-b*~b%d&&g(d,k/=d))(2)?n:f(b,n+1) Try it online! How? Given the base \$b\$, we look for the smallest integer \$n\ge b\$ with a prime divisor \$d\$ which is neither \$n\$ itself nor a divisor of \$b-1\$, \$b\$ or \$b+1\$. Commented f = ( // ...


8

Haskell, 53 bytes f b=[x|x<-[b..],k<-[2..x-1],mod x k+gcd(b^3-b)x<2]!!0 Try it online!


7

Total 36,757,269,913 cycles 830B assembled Number Time (s) Cycles 8831269065180497 0.1 1148 2843901546547359024 55.0 9535194 6111061272747645669 351.4 60559378 11554045868611683619 0.8 135135 6764921230558061729 1.0 155407 16870180535862877896 43067.5 7126449414 ...


7

Pyth - 17 12 11 bytes Thanks to @FryAmTheEggman for fixing my answer and saving a byte. @FmsMty{PdQ Test Suite.


7

Pyth, 11 bytes t@FmsMy{PdQ Input in the form 30,7. t@FmsMy{PdQ implicit: Q=input tuple y powerset of { unique elements of Pd prime factorizations of d sM Map sum over each element of the powerset sMy{Pd lambda d: all sums of unique prime factors of d m Q Map over Q. Produces a ...


Only top voted, non community-wiki answers of a minimum length are eligible