# Tag Info

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. 13 Python 2, 55 bytes f=lambda n,k=2:n/k*and(f(n,k+1),[k]+f(n/k,k))[n%k<1] Try it online! 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 ... 12 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 ṗ --... 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 ... 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 ... 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 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 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. 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 ... 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 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 ...

7

Python 2, 62 57 56 bytes lambda n:max(k%n-n%(k/n+2)**(k%n)*n for k in range(n*n)) Try it online!

7

Jelly, 7 bytes Æs÷$ÞṪ= Try it online! Jelly, 8 bytes Æs÷$ÐṀ⁼W Try it online! Test Suite! Explanation Æs÷$ÐṀ⁼W ~ Full program (monadic). ÐṀ ~ Keep the elements with maximal link value (auto-rangifies). Æs ~ Divisor sum. ÷$ ~ Divide by the current element. ⁼W ~ Check equality with the input wrapped into a singleton. ~ (...

7

Jelly, 10 bytes After a LOT of fiddling around! ÆET0ṪḊ?µl¿ A monadic link taking a positive integer and returning 1 if it is unique or 0 if not. Try it online! How? ÆET0ṪḊ?µl¿ - Link: number, n e.g. 11 or 13 or 20 ¿ - while: l - ...condition: (left) logarithm with base (right) - note: x ...

7

Jelly, 17 bytes Encoder (10 bytes): 0;IA+\‘ÆNP Try it online! Decoder (7 bytes): ÆEĖŒṙḂ¬ Try it online! How? Encoder: 0;IA+\‘ÆNP - Link: list of integers (1s and 0s) e.g. [1,1,1,1,0] 0; - prepend a zero [0,1,1,1,1,0] I - incremental differences [1,0,0,0,-1] A - absolute values ...

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