Definisi : kekuatan prima adalah bilangan alami yang dapat diekspresikan dalam bentuk p n di mana p adalah prima dan n adalah bilangan alami.
Tugas : Diberi kekuatan prima p n > 1, kembalikan prima p.
Testcases :
input output
9 3
16 2
343 7
2687 2687
59049 3
Penilaian : Ini adalah kode-golf . Jawaban terpendek dalam byte menang.
code-golf
arithmetic
primes
king-of-the-hill
python
board-game
code-golf
number
subsequence
code-golf
ascii-art
code-golf
array-manipulation
decision-problem
grid
fastest-algorithm
logic-gates
logic
code-golf
cards
code-golf
rational-numbers
code-golf
math
number
sequence
code-golf
array-manipulation
integer
code-golf
number
array-manipulation
code-golf
number
sequence
decision-problem
code-golf
ascii-art
number
code-challenge
sequence
arithmetic
sorting
code-golf
date
fastest-algorithm
code-golf
string
number
random
combinatorics
code-golf
combinatorics
code-golf
ascii-art
base-conversion
code-golf
array-manipulation
code-golf
string
code-golf
string
number
arithmetic
code-golf
kolmogorov-complexity
code-golf
string
array-manipulation
json
code-golf
puzzle-solver
code-golf
binary
graph-theory
code-golf
arithmetic
haskell
code-golf
string
cipher
code-golf
code-golf
string
parsing
alphabet
code-golf
string
code-golf
ascii-art
code-golf
string
number
code-golf
string
balanced-string
Biarawati Bocor
sumber
sumber
n
1?n = 1
.Jawaban:
Bahasa Pemrograman Shakespeare ,
209207 byteCobalah online!
(I/you)*you<I
lebih pendek dariI%you>0
pada SPL.sumber
05AB1E , 1 byte
Cobalah online!
sumber
[]
sekitar angka) adalah hasil yang valid?f = push list of prime factors (no duplicates)
Java 8,
463937 byte-7 byte secara tidak langsung berkat @Tsathoggua .
-2 byte berkat JoKing
Cobalah online.
Penjelasan:
sumber
n->{for(int i=1;++i<=n;)if(n%i<1)return i;}
untuk mendapatkan 43 karakter? (Saya tidak bisa bahasa Jawa.)n->{for(int i=1;++i<=n;)if(n%i<1)return i;return n;}
akan bekerja, tetapi sayangnya lebih lama. Java dapat memiliki satu pengembalian dalam loop tak terbatas, yang memang menghemat byte, jadi terima kasih!n->{for(int i=1;;)if(n%++i<1)return i;}
. Karenai
akan menjadin
akhirnya (seperti dengan kasus uji2687
) dann%n==0
,i<=n
tidak diperlukan dalam kasus ini.Python 3 ,
3635 byte-1 byte berkat mathmandan
Cobalah online!
Fungsi rekursif yang menemukan faktor pertama lebih besar dari 1
sumber
if/else
denganand/or
. Sepertif=lambda n,x=2:n%x and f(n,x+1)or x
,.MATL ,
43 byteCobalah online!
Penjelasan:
sumber
Spasi ,
806160 byte-20 byte berkat @ JoKing .
Huruf
S
(spasi),T
(tab), danN
(baris baru) ditambahkan hanya sebagai penyorotan.[..._some_action]
ditambahkan sebagai penjelasan saja.Cobalah online (dengan spasi, tab, dan baris baru saja).
Penjelasan dalam pseudo-code:
Contoh dijalankan:
input = 9
Program berhenti dengan kesalahan: Tidak ditemukan jalan keluar.
sumber
i == n
check?n%n
would be 0 anywayn%i
and call the print afterwards?Octave, 16 bytes
Try it online!
Explanation:
Or:
sumber
Funky, 30 bytes
Try it online!
sumber
0==
can be1>
I think.JavaScript (ES6), 25 bytes
Try it online!
sumber
Jelly, 3 bytes
Try it online!
ÆfṪ
,ÆfX
could also be seriously competing functions.ÆfQ
could be a seriously competing full program.sumber
C (gcc), 28 bytes
Try it online!
sumber
Forth (gforth), 34 bytes
Try it online!
Explanation
Code Explanation
sumber
Pyth, 2 bytes
Try it here!
sumber
Brachylog, 2 bytes
Try it online!
Explanation
sumber
J, 4 bytes
Select
{
the first0
of the prime factorsq:
Try it online!
sumber
Neim, 1 byte
Try it online!
sumber
Haskell, 26 bytes
Try it online!
sumber
Mathematica, 17 bytes
The second smallest divisor.
sumber
R,
3226 bytes@Giuseppe with different logic and a shorter solution:
Try it online!
Original:
Try it online!
This is obviously a much superior port of the 05AB1E solution.
sumber
ARBLE, 19 bytes
Try it online!
sumber
Japt
-g
, 1 byteTry it here
sumber
PowerShell, 31 bytes
Try it online!
Constructs a range from
2
to input$a
, pulls out those elementswhere
(?
) the modulo operation%
results in a zero!(...)
(i.e., those that are divisors of$a
), and then takes the smallest[0]
one thereof. That's left on the pipeline, output is implicit.sumber
Perl 6, 22 bytes
Try it online!
Anonymous code block that filters the factors of the range of 2 to the input and returns the first one. I tried using
^$
to save 2 bytes, but that didn't work in the case that the input was prime.sumber
Visual Basic .NET (.NET Framework v4.5),
12371 bytes-52 bytes thanks to @Jo King
Try it online!
Ungolfed:
Explanation:
The
i
loop searches backwards from the first number, and finds all numbers that divide it evenly. Because we are going backwards, the smallest is stored in the vairableA
.VB gives you a free variable that matches your function name (in my case,
A
). At the end of the function execution, the value in that variable is returned (barring an explicitReturn
statement.sumber
Haskell, 29 bytes
Try it online!
sumber
Python 3,
474544 bytesInspired by Kevin Cruijssen's answer in Java.
23 bytes removed thanks to Jo King.Try it online!
sumber
if
, and the condition can be<1
range(n)
and incrementingi
in placePari/GP, 17 bytes
Try it online!
Pari/GP, 17 bytes
Try it online!
sumber
Ruby, 100 bytes
Try it online!
sumber
Stax, 3 bytes
Run and debug it
First element of prime factorization.
sumber
Julia 0.6, 25 bytes
Try it online!
sumber