์ฃผ์š” ๊ฐœ๋ฏธ ๐Ÿœ


50

"ํ”„๋ผ์ž„ ๊ฐœ๋ฏธ"๋Š” ์ •์ˆ˜๋ฅผ ํƒ์ƒ‰ํ•˜๊ณ  ์†Œ์ˆ˜๋งŒ ๋‚จ์„ ๋•Œ๊นŒ์ง€ ์ •์ˆ˜๋ฅผ ๋‚˜๋ˆ„๋Š” ์™„๊ณ ํ•œ ๋™๋ฌผ์ž…๋‹ˆ๋‹ค!


์ฒ˜์Œ์—๋Š” ๋ชจ๋“  ์ •์ˆ˜> = 2๋ฅผ ํฌํ•จํ•˜๋Š” ๋ฌดํ•œ ๋ฐฐ์—ด A๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. [2,3,4,5,6,.. ]

p๋ฐฐ์—ด์—์„œ ๊ฐœ๋ฏธ์˜ ์œ„์น˜๋ฅผ ๋ด…์‹œ๋‹ค . ์ฒ˜์Œ์— p = 0(๋ฐฐ์—ด์€ 0 ์ธ๋ฑ์Šค์ž…๋‹ˆ๋‹ค)

๋งค ์ฐจ๋ก€ ๊ฐœ๋ฏธ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์›€์ง์ž…๋‹ˆ๋‹ค.

  • ๊ฒฝ์šฐ A[p]์†Œ์ˆ˜ ๋‹ค์Œ ์œ„์น˜๋กœ ๊ฐœ๋ฏธ ์ด๋™ :p โ† p+1
  • ๊ฒฝ์šฐ ๋‹ค๋ฅธ, A[p]๋ณตํ•ฉ ์ˆซ์ž๊ฐ€,ํ•˜์ž q์šฐ๋ฆฌ๋Š” ๋ถ„์—ด์˜ ์ž‘์€ ์ œ์ˆ˜> 1. ์ˆ˜ A[p]์— ์˜ํ•ด q, ์šฐ๋ฆฌ๋Š” ์ถ”๊ฐ€ q์— A[p-1]. ๊ฐœ๋ฏธ๊ฐ€ ์ด์ „ ์œ„์น˜๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.p โ† p-1

๊ฐœ๋ฏธ์˜ ์ฒซ ๋ฒˆ์งธ ์›€์ง์ž„์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

 2  3  4  5  6  7  8  9  ... 
 ^
 2  3  4  5  6  7  8  9  ... 
    ^
 2  3  4  5  6  7  8  9  ... 
       ^
 2  5  2  5  6  7  8  9  ... 
    ^
 2  5  2  5  6  7  8  9  ... 
       ^
 2  5  2  5  6  7  8  9  ... 
          ^
 2  5  2  5  6  7  8  9  ... 
             ^
 2  5  2  7  3  7  8  9  ... 
          ^

ํ”„๋กœ๊ทธ๋žจ์€ n์ด๋™ ํ›„ ๊ฐœ๋ฏธ์˜ ์œ„์น˜๋ฅผ โ€‹โ€‹์ถœ๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. (๋‹น์‹ ์€ ๊ฐ€์ • ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค n <= 10000)

ํ…Œ์ŠคํŠธ ์‚ฌ๋ก€ :

0 => 0
10 => 6
47 => 9
4734 => 274
10000 => 512

ํŽธ์ง‘ํ•˜๋‹ค. 1 ์ธ๋ฑ์‹ฑ ๋œ ๋ชฉ๋ก์„ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ์œ„์˜ ํ…Œ์ŠคํŠธ ์‚ฌ๋ก€์— ๋Œ€ํ•ด ๊ฒฐ๊ณผ 1, 7, 10, 275, 513์„ ํ‘œ์‹œ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด๊ฒƒ์€ ์ฝ”๋“œ ๊ณจํ”„์ด๋ฏ€๋กœ ๋ฐ”์ดํŠธ ๋‹จ์œ„์˜ ์ฝ”๋“œ๊ฐ€ ๊ฐ€์žฅ ์งง์€ ์ฝ”๋“œ๊ฐ€ ์šฐ์„ ํ•ฉ๋‹ˆ๋‹ค.


32
๋‚˜๋Š” Hot Network Questions์—์„œ ์ด๊ฒƒ์„ ๋ณด์•˜์„ ๋•Œ ์Šคํฌ๋ฆฐ์— ๊ฐœ๋ฏธ๊ฐ€ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค.
Kodos Johnson

14
์ˆœ์„œ๊ฐ€ ์ž„์˜๋กœ ์ •์˜๋˜์–ด n์žˆ๋Š”์ง€ (๋˜๋Š” ๋ณตํ•ฉ ์ผ€์ด์Šค๊ฐ€ ๊ฐœ๋ฏธ๋ฅผ ์ดˆ๊ธฐ์˜ ์™ผ์ชฝ์œผ๋กœ ๋ฐ€์–ด ๋„ฃ์„ ์ˆ˜ ์žˆ๋Š”์ง€) ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค 2.
Martin Ender

1
@SuperChafouin์ด๋ฏ€๋กœ ํ…Œ์ŠคํŠธ ์‚ฌ๋ก€์˜ ์ถœ๋ ฅ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. 1,7,10,275,5131- ์ธ๋ฑ์‹ฑ์ด ๋ช…์‹œ๋œ ๊ฒฝ์šฐ? ๋˜๋Š” ์—ฌ์ „ํžˆ ์ถœ๋ ฅ๊ณผ ์ผ์น˜ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.
Tom Carpenter

12
@MartinEnder ๋˜ ๋‹ค๋ฅธ ์—ด๋ฆฐ ์งˆ๋ฌธ์€ ํ”„๋ผ์ž„> 7์ด ๊ฒฐ๊ตญ์— ๋‚จ์„ ์ˆ˜ ์žˆ๋Š”์ง€ ์—ฌ๋ถ€์ž…๋‹ˆ๋‹ค.
Arnauld

2
@Arnauld ์ด๋™ n = 1,000,000,000 (์—ฌ๊ธฐ์„œ p = 17156661)๊นŒ์ง€ n๊ณผ p์˜ ๊ด€๊ณ„๋Š” p = n / (ln (n) * ln (ln (n)))์— ๋งค์šฐ ๊ฐ€๊น์Šต๋‹ˆ๋‹ค.
Penguino

๋‹ต๋ณ€:


11

Alice , 45 ๋ฐ”์ดํŠธ

/o
\i@/.&wqh!]k.&[&w;;?c]dt.n$k&;[.?~:![?+!kq

์˜จ๋ผ์ธ์œผ๋กœ ์‚ฌ์šฉํ•ด๋ณด์‹ญ์‹œ์˜ค!

๋Œ€๋ถ€๋ถ„ ๊ฐ„๋‹จํ•œ ๊ตฌํ˜„์ž…๋‹ˆ๋‹ค.

nAlice์˜ ๋ฃจํ•‘ ์‹œ๊ฐ„์€ ์ผ๋ฐ˜์ ์œผ๋กœ ๋ฆฌํ„ด ์ฃผ์†Œ n-1์‹œ๊ฐ„ ์„ ํ‘ธ์‹œ ํ•œ ๋‹ค์Œ์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ ๋ฐ˜๋ณต์˜ ๋์— ๋ฆฌํ„ดํ•˜์—ฌ ์ˆ˜ํ–‰๋ฉ๋‹ˆ๋‹ค k. ๋ฃจํ”„๋ฅผ ํ†ต๊ณผ ํ•œ ๋งˆ์ง€๋ง‰ ์‹œ๊ฐ„์—๋Š” k๋ช…๋ น์ด ๋Œ์•„๊ฐˆ ๊ณณ์ด์—†๊ณ  ์‹คํ–‰์ด ์ง„ํ–‰๋ฉ๋‹ˆ๋‹ค.

์ด ํ”„๋กœ๊ทธ๋žจ์€ ๋™์ผํ•œ k๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ˆซ์ž๊ฐ€ ์†Œ์ˆ˜ ์ผ ๋•Œ ์ผ์ฐ ์ค‘์ง€ํ•ฉ๋‹ˆ๋‹ค. ๊ฒฐ๊ณผ์ ์œผ๋กœ ์ตœ์ข… ๋ฐ˜๋ณต์€ ํ•ญ์ƒ ๊ฐœ๋ฏธ๋ฅผ ์™ผ์ชฝ์œผ๋กœ ์ด๋™์‹œํ‚ต๋‹ˆ๋‹ค. ์ด ๋ฒ„๊ทธ๋ฅผ ๋ณด์ƒํ•˜๊ธฐ ์œ„ํ•ด n+11- ์ธ๋ฑ์Šค ๋ฐฐ์—ด์—์„œ ๋ฐ˜๋ณต์„ ์ˆ˜ํ–‰ํ•˜์—ฌ ์›ํ•˜๋Š” ๊ฒฐ๊ณผ๋ฅผ ์ •ํ™•ํ•˜๊ฒŒ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค ( n=0๋ฌด๋ฃŒ๋กœ ์ œ๊ณต).


7

ํŒŒ์ด์ฌ 2 , 120 ๋ฐ”์ดํŠธ

p=0
A=range(2,input()+2)
for _ in A:
 for q in range(2,A[p]):
	if A[p]%q<1:A[p]/=q;p-=1;A[p]+=q;break
 else:p+=1
print p

์˜จ๋ผ์ธ์œผ๋กœ ์‚ฌ์šฉํ•ด๋ณด์‹ญ์‹œ์˜ค!

์•„, ๋ ˆ์–ด forโ€“ else๋ฃจํ”„! ์ด ๋ณธ๋ฌธ์€์„ ํ†ตํ•ด ๋ณธ๋ฌธ์„ ์ข…๋ฃŒ ํ•˜์ง€ ์•Š์€else ๊ฒฝ์šฐ์—๋งŒ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค . ์šฐ๋ฆฌ์˜ ๊ฒฝ์šฐ์—, ์ด๊ฒƒ์€ ์šฐ๋ฆฌ๊ฐ€ ๋ชจ๋“  s๋ฅผ ์ ๊ฒ€ ํ–ˆ๊ณ  ๊ทธ๊ฒƒ๋“ค ์ค‘ ์–ด๋Š ๊ฒƒ๋„ ๋‚˜๋ˆ„์ง€ ์•Š์•˜๋‹ค๋Š” ๊ฒƒ์„ ์˜๋ฏธ ํ•ฉ๋‹ˆ๋‹ค .forbreakqp


7

์˜ฅํƒ€๋ธŒ , 109103101 94 ๋ฐ”์ดํŠธ

function i=a(n)i=1;for l=z=2:n+1
if nnz(q=factor(z(i)))>1
z(i--)/=p=q(1);z(i--)+=p;end
i++;end

์˜จ๋ผ์ธ์œผ๋กœ ์‚ฌ์šฉํ•ด๋ณด์‹ญ์‹œ์˜ค!

์ด ์ฝ”๋“œ๋Š” 1- ์ธ๋ฑ์‹ฑ์—์„œ ์œ„์น˜๋ฅผ ์ถœ๋ ฅํ•˜๋ฏ€๋กœ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ์ถœ๋ ฅ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

0 => 1
10 => 7
47 => 10
4734 => 275
10000 => 513

์ด ๋ฒ„์ „์€ ์ผ๋ถ€ Octave ์ตœ์ ํ™”๋ฅผ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ MATLAB๊ณผ ํ˜ธํ™˜๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์•„๋ž˜ ์ฝ”๋“œ๋Š” MATLAB ํ˜ธํ™˜ ๋ฒ„์ „์ž…๋‹ˆ๋‹ค.


MATLAB, 130 123 118 117 ๋ฐ”์ดํŠธ

function i=a(n)
z=2:n+1;i=1;for l=z
q=factor(z(i));if nnz(q)>1
z(i)=z(i)/q(1);i=i-1;z(i)=z(i)+q(1);else
i=i+1;end
end

Octave ๋ฒ„์ „๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ 1- ์ธ๋ฑ์‹ฑ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. MATLAB์˜ ๋ชจ๋“  ํ…Œ์ŠคํŠธ ์‚ฌ๋ก€์— ๋Œ€ํ•ด ํ…Œ์ŠคํŠธํ–ˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด 100000์˜ ์ถœ๋ ฅ์€ 3675 (1 ์ธ๋ฑ์‹ฑ)์ž…๋‹ˆ๋‹ค.

์œ„ ์ฝ”๋“œ์˜ ์ฃผ์„์ด ๋‹ฌ๋ฆฐ ๋ฒ„์ „ :

function i=a(n)
    z=2:n+1;                %Create our field of numbers
    i=1;                    %Start of at index of 1 (MATLAB uses 1-indexing)
    for l=1:n               %For the required number of iterations
        q=factor(z(i));     %Calculate the prime factors of the current element
        if nnz(q)>1         %If there are more than one, then not prime
            z(i)=z(i)/q(1); %So divide current by the minimum
            i=i-1;          %Move back a step
            z(i)=z(i)+q(1); %And add on the minimum to the previous.
        else
            i=i+1;          %Otherwise we move to the next step
        end
    end

๊ด€์‹ฌ์˜ ๋Œ€์ƒ์œผ๋กœ, ์ด๊ฒƒ์€ n์˜ ์ฒซ 10000 ๊ฐ’์— ๋Œ€ํ•œ ๊ฐœ๋ฏธ ์œ„์น˜ ๋Œ€ ๋ฐ˜๋ณต ํšŸ์ˆ˜์ž…๋‹ˆ๋‹ค.

๊ฐœ๋ฏธ ์œ„์น˜

๊ฐœ๋ฏธ๋Š” ์•„๋งˆ๋„ ๋ฌดํ•œํ•œ ๊ฒฝํ–ฅ์ด์žˆ์„ ๊ฒƒ ๊ฐ™์ง€๋งŒ, ์•Œ๊ณ ์žˆ๋Š” ์‚ฌ๋žŒ์€๊ธฐ๋งŒ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


  • MATLAB : ๋Œ€๊ด„ํ˜ธ๋ฅผ ์ œ๊ฑฐํ•˜๋Š” for๋Œ€์‹  6 ๋ฐ”์ดํŠธ๋ฅผ ์ ˆ์•ฝ whileํ–ˆ์Šต๋‹ˆ๋‹ค. if-Thanks @Giuseppe
  • MATLAB : 2 ๋ฐ”์ดํŠธ ์ €์žฅ-๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค @Sanchises
  • ์˜ฅํƒ€๋ธŒ : ์˜ฅํƒ€๋ธŒ \=์™€ +=์—ฐ์‚ฐ ์„ ์‚ฌ์šฉํ•˜์—ฌ 10 ๋ฐ”์ดํŠธ ์ ˆ์•ฝ -Thanks @Giuseppe
  • ์˜ฅํƒ€๋ธŒ : 2 ๋ฐ”์ดํŠธ๋ฅผ ์ €์žฅ i++ํ•˜๊ณ  i--- ๊ฐ์‚ฌ @LuisMendo
  • ์˜ฅํƒ€๋ธŒ : 7 ๋ฐ”์ดํŠธ ์ €์žฅ-๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค @Sanchises

TIO์—์„œ ์ž‘๋™ํ•˜๋ ค๋ฉด endํ•จ์ˆ˜ ์‹œ๊ทธ๋‹ˆ์ฒ˜์™€ ์ผ์น˜ ํ•ด์•ผํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.
Giuseppe

@ ์ฃผ์„ธํŽ˜ ์•„, ์•Œ์•˜์–ด. MATLAB์—์„œ ํ›„ํ–‰ end์€ ์„ ํƒ ์‚ฌํ•ญ์ž…๋‹ˆ๋‹ค.
Tom Carpenter

ํ•จ์ˆ˜ i = a (n) ๋Œ€์‹  @ (n)์„ ์‚ฌ์šฉํ•˜์—ฌ ์ต๋ช… ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
Michthan

@Michthan์€ MATLAB์—์„œ ๊ทธ๋ ‡๊ฒŒ ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ๋ฃจํ”„๊ฐ€ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์˜ฅํƒ€๋ธŒ์—์„œ๋„ ๊ฐ€๋Šฅํ•˜์ง€ ์•Š๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๊นŒ?
Tom Carpenter

1
end์˜ฅํƒ€๋ธŒ์—์„œ๋„ ํ›„ํ–‰ ์€ ์„ ํƒ ์‚ฌํ•ญ์ž…๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์—๋Š” ํ•จ์ˆ˜ ๋’ค์— ์ฝ”๋“œ๊ฐ€ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
Luis Mendo

6

์ž๋ฐ” ์Šคํฌ๋ฆฝํŠธ (ES6), 91 ๋ฐ”์ดํŠธ

f=(n,a=[p=0])=>n--?f(n,a,(P=n=>++x<n?n%x?P(n):a[a[p]/=x,--p]+=x:p++)(a[p]=a[p]||p+2,x=1)):p

๋ฐ๋ชจ

์ฃผ์˜ : ๋ชจ๋“  ํ…Œ์ŠคํŠธ ์‚ฌ๋ก€๋ฅผ ํ†ต๊ณผํ•˜๋ ค๋ฉด ์—”์ง„์˜ ๊ธฐ๋ณธ ์Šคํƒ ํฌ๊ธฐ๋ฅผ ๋Š˜๋ ค์•ผ ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

์˜จ๋ผ์ธ์œผ๋กœ ์‚ฌ์šฉํ•ด๋ณด์‹ญ์‹œ์˜ค!


6

ํ•˜์Šค์ผˆ , 108 (106) 94 ๋ฐ”์ดํŠธ

([0]#[2..]!!)
(a:b)#(p:q)=length b:([b#(a+d:div p d:q)|d<-[2..p-1],mod p d<1]++[(p:a:b)#q])!!0

์˜จ๋ผ์ธ์œผ๋กœ ์‚ฌ์šฉํ•ด๋ณด์‹ญ์‹œ์˜ค! ์‚ฌ์šฉ๋ฒ• ์˜ˆ : ([0]#[2..]!!) 10์ˆ˜์œจ 6(0 ์ƒ‰์ธ).

์ด ํ•จ์ˆ˜ #๋Š” ๋ฐฐ์—ด์˜ ์•ž๋ฉด ๋ฐ˜์ „ [p-1, p-2, ..., 1]๊ณผ ๋ฐฐ์—ด ์˜ ๋‚˜๋จธ์ง€ ๋‚˜๋จธ์ง€ ๋‘ ๋ชฉ๋ก์—์„œ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค [p, p+1, p+2, ...]. n์ž…๋ ฅ์ด ์ฃผ์–ด์ง€๋ฉด th ์œ„์น˜๊ฐ€ ๋ฆฌํ„ด ๋˜๋Š” ๋ฌดํ•œ ์œ„์น˜ ๋ชฉ๋ก์„ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค n.

์ด ํŒจํ„ด ((a:b)#(p:q))์€ p๊ฐœ๋ฏธ์˜ ํ˜„์žฌ ์œ„์น˜ a๊ฐ’๊ณผ ์ด์ „ ์œ„์น˜ ๊ฐ’์— ๋ฐ”์ธ๋”ฉ ๋ฉ๋‹ˆ๋‹ค . bํ–‰ 1์˜ ์œ„์น˜์—์„œ ์ƒ๊ธฐ ์–ด๋ ˆ์ด์˜ ์ ‘๋‘์‚ฌ p-2๋ฐ q์œ„์น˜๋ถ€ํ„ฐ ๋ฌดํ•œ ๋‚˜๋จธ์ง€ p+1.

์šฐ๋ฆฌ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฐฉ์‹์œผ๋กœ ์žฌ๊ท€ ํ˜ธ์ถœ ๋ชฉ๋ก์„ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค. ์šฐ๋ฆฌ d๋Š” p(1๋ณด๋‹ค ํฌ๊ณ  ์ž‘์€ p)์˜ ์ œ์ˆ˜ ๋ฅผ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ๋ณด๊ณ  b#(a+d:div p d:q)๊ฐ๊ฐ์— ๋Œ€ํ•ด ๋”ํ•ฉ๋‹ˆ๋‹ค. ์ฆ‰, ํ˜„์žฌ ๊ฐ’ p์„ ๋‚˜๋ˆˆ ๊ฐ’ d๊ณผ ๊ฐœ๋ฏธ ์ด๋™ ์™ผ์ชฝ์— ํ•œ ๋‹จ๊ณ„ d๊ฐ€ ์ถ”๊ฐ€๋ฉ๋‹ˆ๋‹ค a. ๊ทธ๋Ÿฐ ๋‹ค์Œ (p:a:b)#q์ด ๋ชฉ๋ก์˜ ๋์— ์ถ”๊ฐ€ ํ•˜์—ฌ ๊ฐœ๋ฏธ๊ฐ€ ํ•œ ๋‹จ๊ณ„ ์˜ค๋ฅธ์ชฝ์œผ๋กœ ์ด๋™ ํ•จ์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.

๊ทธ๋Ÿฐ ๋‹ค์Œ ๋ชฉ๋ก์—์„œ ํ•ด๋‹น ์žฌ๊ท€ ํ˜ธ์ถœ ์ค‘ ์ฒซ ๋ฒˆ์งธ๋ฅผ ๊ฐ€์ ธ ์™€์„œ ํ˜„์žฌ ์œ„์น˜ ์•ž์— ๋ถ™์Šต๋‹ˆ๋‹ค b. ์ด ์œ„์น˜๋Š” ์ ‘๋‘์‚ฌ ๋ชฉ๋ก์˜ ๊ธธ์ด์™€ ์ผ์น˜ํ•ฉ๋‹ˆ๋‹ค . ์ œ์ˆ˜๊ฐ€ ์˜ค๋ฆ„์ฐจ์ˆœ์ด๋ฏ€๋กœ ์žฌ๊ท€ ํ˜ธ์ถœ ๋ชฉ๋ก์—์„œ ์ฒซ ๋ฒˆ์งธ๋ฅผ ์„ ํƒํ•˜๋ฉด ๊ฐ€์žฅ ์ž‘์€ ๊ฒƒ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ (p:a:b)#q๋ชฉ๋ก ๋์— ์ถ”๊ฐ€ p๋˜๋ฏ€๋กœ ์ œ์ˆ˜๊ฐ€์—†๋Š” ๊ฒฝ์šฐ์—๋งŒ ์„ ํƒ ๋˜๋ฏ€๋กœ ์†Œ์ˆ˜์ž…๋‹ˆ๋‹ค.

ํŽธ์ง‘ :
๊ธฐ๋Šฅ ๋ชฉ๋ก์„ ๋‚ด๋ฆผ์ฐจ์ˆœ์—์„œ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ „ํ™˜ํ•˜์—ฌ -2 ๋ฐ”์ดํŠธ
์นด์šดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š๊ณ  0 ์ธ๋ฑ์‹ฑ์œผ๋กœ ์ „ํ™˜ํ•˜์—ฌ ๋ฌดํ•œ ๋ชฉ๋ก์œผ๋กœ ์ธ๋ฑ์‹ฑํ•˜๋Š” Zgarb์˜ ์•„์ด๋””์–ด ๋•๋ถ„์— -12 ๋ฐ”์ดํŠธ.


2
์นด์šดํ„ฐ๋ฅผ ์˜ฎ๊ธฐ๋Š” ๋Œ€์‹  ๋ฌดํ•œ ๋ชฉ๋ก๊ณผ ์ƒ‰์ธ ์ƒ์„ฑ์„ ํ†ตํ•ด 96 ๋ฐ”์ดํŠธ .
Zgarb

1
@ Zgarb ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! 0 ์ธ๋ฑ์‹ฑ์œผ๋กœ ์ „ํ™˜ ํ•  ๋•Œ์กฐ์ฐจ 94 ๋ฐ”์ดํŠธ์ž…๋‹ˆ๋‹ค.
Laikoni

5

TI-BASIC, 108 (103) 102 98 ๋ฐ”์ดํŠธ

์ž…๋ ฅ ๋ฐ ์ถœ๋ ฅ์€์— ์ €์žฅ๋ฉ๋‹ˆ๋‹ค Ans. ์ถœ๋ ฅ์€ 1 ์ธ๋ฑ์Šค์ž…๋‹ˆ๋‹ค.

Ansโ†’N
seq(X,X,2,9ยณโ†’A
1โ†’P
For(I,1,N
1โ†’X:โˆŸA(Pโ†’V
For(F,2,โˆš(V
If X and not(fPart(V/F:Then
DelVar XV/Fโ†’โˆŸA(P
P-1โ†’P
F+โˆŸA(Pโ†’โˆŸA(P
End
End
P+Xโ†’P
End

๋‹น์‹ ์€ ๋–จ์–ด์ ธ ๋ฐ”์ดํŠธ๋ฅผ ์ทจํ•  ์ˆ˜ fPart(โˆŸA(P)/F:์™€ fPart(FยนโˆŸA(P:. ๋‹ค์Œ ์ค„์—์„œ๋„ ๋งˆ์ฐฌ๊ฐ€์ง€์ž…๋‹ˆ๋‹ค.
Scott Milner

@ScottMilner ํ•ญ์ƒ ์ž‘๋™ํ•˜์ง€๋Š” ์•Š์Šต๋‹ˆ๋‹ค. not(fPart(7โปยน70์ด์ง€๋งŒ not(fPart(7/71์ž…๋‹ˆ๋‹ค.
kamoroso94

5

MATL , 41 ๋ฐ”์ดํŠธ

:Q1y"XHyw)Zp?5MQ}1MtYf1)/H(8MyfHq=*+9M]]&

์ถœ๋ ฅ์€ 1 ๊ธฐ๋ฐ˜์ž…๋‹ˆ๋‹ค. ์˜จ๋ผ์ธ ํ†ต์—ญ์‚ฌ์˜ ๋งˆ์ง€๋ง‰ ํ…Œ์ŠคํŠธ ์‚ฌ๋ก€์— ๋Œ€ํ•œ ํ”„๋กœ๊ทธ๋žจ ์‹œ๊ฐ„์ด ์ดˆ๊ณผ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

์˜จ๋ผ์ธ์œผ๋กœ ์‚ฌ์šฉํ•ด๋ณด์‹ญ์‹œ์˜ค!

์„ค๋ช…

ํ”„๋กœ๊ทธ๋žจ์€ ์ฑŒ๋ฆฐ์ง€์— ์„ค๋ช… ๋œ ์ ˆ์ฐจ๋ฅผ ์ ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ์œ„ํ•ด MATL์˜ ์ˆ˜๋™ ๋ฐ ์ž๋™ ํด๋ฆฝ ๋ณด๋“œ๋ฅผ ๋น„์ •์ƒ์ ์œผ๋กœ ๋งŽ์ด ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

๊ฐ€์žฅ ์ž‘์€ ์ œ์ˆ˜๋Š” ์†Œ์ธ์ˆ˜ ๋ถ„ํ•ด์˜ ์ฒซ ๋ฒˆ์งธ ํ•ญ๋ชฉ์œผ๋กœ ๊ตฌํ•ฉ๋‹ˆ๋‹ค.

"๋ถ„ํ• "์—…๋ฐ์ดํŠธ๋Š” ๋ฐฐ์—ด A ์˜ ํ•ด๋‹น ํ•ญ๋ชฉ์„ ๋ฎ์–ด ์จ์„œ ์ˆ˜ํ–‰๋ฉ๋‹ˆ๋‹ค . "์ถ”๊ฐ€"์—…๋ฐ์ดํŠธ ์†Œ์ž ํ˜„๋ช…ํ•œ์— ์ฒจ๊ฐ€ํ•จ์œผ๋กœ์จ ์ˆ˜ํ–‰๋œ๋‹ค ์›ํ•˜๋Š” ์œ„์น˜์—์„œ๋ฅผ ์ œ์™ธํ•˜๊ณ  0์„ ํฌํ•จํ•˜๋Š” ๋ฐฐ์—ด.

:Q        % Implicitly input n. Push array [2 3 ... n+1]. This is the initial array A. 
          % It contains all required positions. Some values will be overwritten
1         % Push 1. This is the initial value for p
y         % Duplicate from below
"         % For each loop. This executes the following n times.
          %   STACK (contents whosn bottom to top): A, p
  XH      %   Copy p into clipboard H
  y       %   Duplicate from below. STACK: A, p, A
  w       %   Swap. STACK: A, A, p
  )       %   Reference indexing. STACK: A, A[p]
  Zp      %   Isprime. STACK: A, false/true
  ?       %   If true (that is, if A[p] is prime)
    5M    %     Push p from automatic clipboard. STACK: A, p
    Q     %     Add 1. STACK: A, p+1
  }       %   Else (that is, if A[p] is not prime)
    1M    %     Push A[p] from automatic clipboard. STACK: A, A[p]
    t     %     Duplicate. STACK: A, A[p], A[p]
    Yf    %     Prime factors, with repetitions. STACK: A, A[p], prime factors of A[p]
    1)    %     Get first element, d. STACK: A, A[p], d
    /     %     Divide. STACK: A, A[p]/d
    H     %     Push p from clipboard H. STACK: A, A[p]/d, p
    (     %     Assignment indexing: write value. STACK: A with A[p] updated
    8M    %     Push d from automatic clipboard.
    y     %     Duplicate from below. STACK: A with A[p] updated, d, A with A[p] updated
    f     %     Find: push indices of nonzero entries.
          %     STACK: A with A[p] updated, d, [1 2 ... n]
    Hq    %     Push p from clipboard H, subtract 1.
          %     STACK: A with A[p] updated, d, [1 2 ... n], p-1
    =     %     Test for equality, element-wise.
          %     STACK: A with A[p] updated, d, [0 ... 0 1 0 ... 0]
    *     %     Multiply, element-wise. STACK: A with A[p] updated, [0 ... 0 d 0 ... 0]
    +     %     Add, element-wise. STACK: A with A[p-1] and A[p] updated
    9M    %     Push p-1 from automatic clipboard.
          %     STACK: A with A[p-1] and A[p] updated, p-1
  ]       %   End if. The stack contains the updated array and index
]         % End for each. Process the next iteration
&         % Specify that the following implicit display function should display only
          % the top of the stack. Implicitly display


3

PARI / GP, 87 ๋ฐ”์ดํŠธ

f(n)=A=[2..9^5];p=1;for(i=1,n,q=factor(A[p])[1,1];if(A[p]-q,A[p]/=q;p--;A[p]+=q,p++));p

๊ฝค ์ž๊ธฐ ์„ค๋ช… ์  (๊ทธ๋ ‡์ง€ ์•Š์€ ๊ณจํ”„). f(n)=๋ถ€ํ’ˆ์„ ๊ณ„์‚ฐํ•˜์ง€ ์•Š์œผ๋ฉด 82 ๋ฐ”์ดํŠธ์ž…๋‹ˆ๋‹ค. n->(85 ๋ฐ”์ดํŠธ)๋กœ ์‹œ์ž‘ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค .

1 ์ธ๋ฑ์Šค ์–ธ์–ด์ž…๋‹ˆ๋‹ค.


ํŽธ์ง‘ : ์ˆ˜์ • illustrate(n,m)=A=[2..m+1];p=1;for(i=1,n,for(j=1,m,printf("%5s",if(j==p,Str(">",A[j],"<"),Str(A[j]," "))));print();q=factor(A[p])[1,1];if(A[p]!=q,A[p]/=q;p--;A[p]+=q,p++))์€ ๊ฐœ๋ฏธ ์‚ฐ์ฑ…์˜ ๊ทธ๋ฆผ์„ ์ธ์‡„ํ•ฉ๋‹ˆ๋‹ค (๋„“์€ ํ„ฐ๋ฏธ๋„์ด ์ฃผ์–ด์ง). ์˜ˆ๋ฅผ ๋“ค์–ด ๋‹ค์Œ illustrate(150,25)๊ณผ ๊ฐ™์ด 25 ๊ฐœ์˜ ์—ด์— ์ฒ˜์Œ 150 ๊ฐœ์˜ ๋‹จ๊ณ„๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

  > 2 <34 5678 9 10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26
   2> 3 <4 5 6 7 8 9 10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26
   2 3> 4 <5678 9 10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26
   2> 5 <2 5 6 7 8 9 10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26
   2 5> 2 <5678 9 10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 2> 5 <6 7 8 9 10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26
   25 5> 6 <7 8 9 10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26
   2 5> 7 <3 7 8 9 10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26
   25 5> 3 <7 8 9 10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3 3> 7 <8 9 10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3 7> 8 <9 10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3 3> 9 <4 9 10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26
   25 5> 6 <34 9 10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26
   2 5> 9 <3 34 9 10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26
   2 5> 5 <34 34 9 10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 5> 3 <34 34 9 10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3> 3 <34 9 10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3 3> 3 <4 9 10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3 3 3> 4 <9 10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3 3> 5 <2 9 10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3 3 5> 2 <9 10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3 3 5 2> 9 <10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3 3 5> 5 <3 10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3 3 5 5> 3 <10 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3 3 5 5 3> 10 <11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3 3 5 5> 5 <5 11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3 3 5 5 5> 5 <11 12 1314 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3 3 5 5 5 5> 11 <12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3 3 5 5 5 5 11> 12 <13 14 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3 3 5 5 5 5> 13 <6 13 14 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3 3 5 5 5 5 13> 6 <13 14 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3 3 5 5 5 5> 15 <3 13 14 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3 3 5 5 5> 8 <5 3 13 14 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3 3 5 5> 7 <4 5 3 13 14 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3 3 5 5 7> 4 <5 3 13 14 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3 3 5 5> 9 <2 5 3 13 14 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3 3 5> 8 <3 2 5 3 13 14 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3 3> 7 <4 3 2 5 3 13 14 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3 3 7> 4 <34 34 13 14 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3 3> 9 <2 3 2 5 3 13 14 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 3> 6 <3 2 3 2 5 3 13 14 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 5> 5 <3 34 34 5 1 14 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 5> 3 <3 2 3 2 5 3 13 14 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 5 3> 3 <2 3 2 5 3 13 14 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 3> 2 <3 2 5 3 13 14 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 3 2> 3 <2 5 3 13 14 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 3> 2 <5 3 13 14 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 3 2> 5 <3 13 14 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 34 34 5> 3 <13 14 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 34 34 5> 13 <14 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 34 5 13> 14 <15 16 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 34 5 3> 15 <7 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 3 2 5> 6 <5 7 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 3 2> 7 <35 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 3 2 7> 3 <5 7 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 34 34 3> 5 <7 15 16 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 34 34 34> 7 <15 16 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 34 34 34> 15 <16 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 3 34 34 5> 10 <5 16 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 34 34 3> 7 <5 5 16 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 34 34 34> 5 <5 16 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 34 34 34 5> 5 <16 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 34 34 34 5> 16 <17 18 19 20 21 22 23 24 25 26
   2 5 5 3 34 34 34 5> 7 <8 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 34 34 34 5> 8 <17 18 19 20 21 22 23 24 25 26
   2 5 5 3 34 34 34 5> 9 <4 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 34 34 34> 8 <34 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 34 34 3> 9 <44 34 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 3 2 7> 6 <34 34 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 3 2> 9 <3 34 34 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 3> 5 <3 3 34 34 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 3 5> 3 <3 34 34 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3> 3 <34 34 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 34 5 3> 3 <4 34 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3> 4 <34 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3> 5 <2 3 4 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 34 5 3 3> 2 <34 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2> 3 <4 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 3> 4 <17 18 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2> 5 <2 17 18 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5> 2 <17 18 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 2> 17 <18 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 34 5 3 3 5 2 17> 18 <19 20 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 2> 19 <9 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 19 2> 9 <19 20 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 2> 22 <3 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5> 4 <11 3 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2> 7 <2 11 3 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 7> 2 <11 3 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 7 2> 11 <3 19 20 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 7 2 11> 3 <19 20 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 7 2 11 3> 19 <20 21 22 23 24 25 26
   2 5 5 3 3 2 34 5 34 5211 11 3 19> 20 <21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 7 2 11 3> 21 <10 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 7 2 11> 6 <7 10 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 7 2> 13 <3 7 10 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 7 2 13> 3 <7 10 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 7 2 13 3> 7 <10 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 7 2 13 3 7> 10 <21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 7 2 13 3> 9 <5 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 7 2 13> 6 <3 5 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 7 2> 15 <3 3 21 21 23 23 25 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 7> 5 <5 3 5 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 7 5> 5 <3 3 5 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 5> 3 <3 5 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 5 3> 3 <5 21 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 5 3 3> 5 <21 22 23 24 25 26
   2 5 5 3 3 2 34 5 3 3 5 5 5 3 3 5> 21 <22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 5 5 3 3> 8 <7 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 5 3> 5 <4 7 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 5 3 5> 4 <7 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 5 3> 7 <2 7 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 5 5 3 7> 2 <7 22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 5 3 7 2> 7 <22 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 5 5 3 7 2 7> 22 <23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 5 5 3 7 2> 9 <11 23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 5 3 7> 5 <3 11 23 24 25 26
   2 5 5 5 3 3 2 3 5 3 3 5 2 5 5 3 7 5> 3 <11 โ€‹โ€‹23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 5 5 3 7 5 3> 11 <23 24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 5 3 7 5 3 11> 23 <24 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 5 3 7 5 3 11 23> 24 <25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 5 3 7 5 3 11> 25 <12 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 5 3 7 5 3> 16 <5 12 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 5 3 7 5> 5 <8 5 12 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 5 3 7 5 5> 8 <5 12 25 26
   2 5 5 5 3 3 2 3 5 3 3 5 2 5 5 3 7 5> 7 <4 5 12 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 5 3 7 5 7> 4 <5 12 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 5 3 7 5> 9 <2 5 12 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 5 3 7> 8 <3 2 5 12 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 5 3> 9 <4 3 5 12 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 5> 6 <34 34 5 12 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 7 5> 7 <3 34 34 5 12 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 7 5 7> 3 <34 34 5 12 25 26
   2 5 5 3 3 2 3 5 3 3 5 5 5 7 3> 3 <4 3 2 5 12 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 5 3 3> 4 <3 2 5 12 25 26
   2 5 5 3 3 2 3 5 3 3 5 7 5 7 3> 5 <2 3 2 5 12 25 26
   2 5 5 3 3 2 3 5 3 3 5 7 5 7 3 5> 2 <3 2 5 12 25 26
   2 5 5 5 3 3 2 3 5 3 3 5 7 5 7 3 5 2> 3 <2 5 12 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 5 3 3 5 2 3> 2 <5 12 25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 5 3 3 5 2 3 2> 5 <12 25 26
   2 5 5 5 3 3 2 3 5 3 3 5 7 5 7 3 5 2 3 2 5> 12 <25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 5 7 3 5 2 3 2> 7 <6 25 26
   2 5 5 5 3 3 2 3 5 3 3 5 2 7 5 7 3 5 2 3 2 7> 6 <25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 5 3 3 5 2 3 2> 9 <3 25 26
   2 5 5 5 3 3 2 3 5 3 3 5 7 5 7 3 5 2 3> 5 <3 3 25 26
   2 5 5 5 3 3 2 3 5 3 3 5 7 5 7 3 5 2 3 5> 3 <3 25 26
   2 5 5 5 3 3 2 3 5 3 3 5 7 5 7 3 5 2 3 5 3> 3 <25 26
   2 5 5 3 3 2 3 5 3 3 5 2 5 5 3 3 5 2 3 5 3 3> 25 <26
   2 5 5 5 3 3 2 3 5 3 3 5 7 5 7 3 5 2 3 5 3> 8 <5 26
   2 5 5 5 3 3 2 3 5 3 3 5 2 7 5 7 3 5 2 3 5> 5 <4 5 26
   

2

ํŒŒ์ด์ฌ (2) , 142 (127) ๋ฐ”์ดํŠธ

  • Sherlock9 ๋•๋ถ„์— 15 ๋ฐ”์ดํŠธ๋ฅผ ์ ˆ์•ฝํ–ˆ์Šต๋‹ˆ๋‹ค .
T=range(2,input()+2);p=0
for _ in T:
 m=T[p];d=min(k for k in range(2,m+1)if m%k<1);p+=1
 if d<m:T[p-1]/=d;p-=2;T[p]+=d
print p

์˜จ๋ผ์ธ์œผ๋กœ ์‚ฌ์šฉํ•ด๋ณด์‹ญ์‹œ์˜ค!




@FelipeNardiBatista ๋ถˆํ–‰ํžˆ๋„, ๊ท€ํ•˜์˜ ์ œ์•ˆ์€ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์— ์ ์šฉ๋˜์ง€ ์•Š๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹คn<=4
Sherlock9

2

Mathematica, 118103 ๋ฐ”์ดํŠธ

(s=Range[2,5^6];t=1;Do[If[PrimeQ@s[[t]],t++,s[[t]]/=(k=#2&@@ Divisors@s[[t]]);s[[t-1]]+=k;t--],#];t-1)&


์˜จ๋ผ์ธ์œผ๋กœ ์‚ฌ์šฉํ•ด๋ณด์‹ญ์‹œ์˜ค!

๋งˆํ‹ด ์—”๋” 15 ๋ฐ”์ดํŠธ ์ ˆ์•ฝ


์•ž์— ๊ณต๋ฐฑ ๊ณต๊ฐ„์ด ์žˆ๊ณ ์— Divisors๋Œ€ํ•œ ํ‘œ๊ธฐ๋ฒ•์„ ์‚ฌ์šฉํ•  Do์ˆ˜ ์žˆ์œผ๋ฉฐ t๋Œ€์‹  t-1(1 ๊ธฐ๋ฐ˜ ๊ฒฐ๊ณผ) ๋Œ€์‹  ๋ฐ˜ํ™˜ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค .
Martin Ender

2

ํŒŒ์ด์ฌ (3) , 158 (149) 133 ๋ฐ”์ดํŠธ

์ด๊ฒƒ์€ ์ฝ”๋“œ๊ฐ€ ๋ชจ๋“  ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์—์„œ ์ž‘๋™ํ•˜๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด ํ•˜๋‚˜ ๋˜๋Š” ๋‘ ๊ฐœ์˜ ์ฟผํฌ๊ฐ€์žˆ๋Š” ๊ฐ„๋‹จํ•œ ์ ˆ์ฐจ ๊ตฌํ˜„์ž…๋‹ˆ๋‹ค. ๋‚ด๊ฐ€ ์‚ฌ์šฉ [*range(2,n+9)](๋ฅผ ์ œ์™ธํ•˜๊ณ  ํฌ๊ธฐ๊ฐ€ ์ถฉ๋ถ„ํ•œ ์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด n<3, n+9์ถฉ๋ถ„ํ•œ ์ด์ƒ์ž…๋‹ˆ๋‹ค). ์ด else์ ˆ์€ old A[p]๋ฅผ d, decrements๋กœ ๋‚˜๋ˆˆ p๋‹ค์Œ dnew์— ์ถ”๊ฐ€ ํ•ฉ๋‹ˆ๋‹ค. A[p]์ด๋Š” ๋ถ„๋ช…ํžˆ ๋‚˜์œ ์ฝ”๋”ฉ ๊ด€ํ–‰์ž…๋‹ˆ๋‹ค. ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ๋งค์šฐ ๊ฐ„๋‹จํ•ฉ๋‹ˆ๋‹ค. ๊ณจํ”„ ์ œ์•ˆ์„ ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค!

ํŽธ์ง‘ :sympy Halvard Hummel ๋•๋ถ„์— -9 ๋ฐ”์ดํŠธ . Felipe Nardi Batista์—์„œ -14 ๋ฐ”์ดํŠธ, Jonathan Frech์˜ Python 2 ์—์„œ ์–ป์€ ์ผ๋ถ€ ์‹ ํ˜ธ์—์„œ -6 ๋ฐ”์ดํŠธ

p,_,*A=range(int(input())+2)
for _ in A:
 m=A[p];d=min(k for k in range(2,m+1)if m%k<1);p+=1
 if d<m:A[p-1]//=d;p-=2;A[p]+=d
print(p)

์˜จ๋ผ์ธ์œผ๋กœ ์‚ฌ์šฉํ•ด๋ณด์‹ญ์‹œ์˜ค!



์ „์ฒด ํ”„๋กœ๊ทธ๋žจ์œผ๋กœ 148 ๋ฐ”์ดํŠธ
Felipe Nardi Batista

if d-m:A[p]...๊ทธ๋ฆฌ๊ณ  else:p+=1๋ฐ”์ดํŠธ ์ €์žฅ
ํŽ ๋ฆฌํŽ˜ ๋‚˜๋ฅด๋”” ๋ฐ”ํ‹ฐ์Šคํƒ€

else๋ช…๋ น๋ฌธ ์„ ์ œ๊ฑฐํ•˜์—ฌ 143 ๋ฐ”์ดํŠธ
Felipe Nardi Batista

, ์ œ๊ฑฐ ํ›„ else๋ฌธ์„ ๊ธฐ๋Šฅ ๋ฒ„์ „ ๋ฐ”์ดํŠธ์˜ ์ฐจ์ด๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค
ํŽ ๋ฆฌํŽ˜ ๋‚˜๋ฅด๋”” ๋ฐ”ํ‹ฐ์Šคํƒ€

2

PHP, 102 + 1 ๋ฐ”์ดํŠธ

for($a=range(2,$argn);$argn--;$d<$a[+$p]?$a[$p--]/=$d+!$a[$p]+=$d:$p++)for($d=1;$a[+$p]%++$d;);echo$p;

ํŒŒ์ดํ”„๋กœ ์‹คํ–‰ -Rํ•˜๊ฑฐ๋‚˜ ์˜จ๋ผ์ธ์œผ๋กœ ์‚ฌ์šฉํ•ด๋ณด์‹ญ์‹œ์˜ค .

์ž…๋ ฅ์„์œ„ํ•œ ๋นˆ ์ถœ๋ ฅ 0; ๋ฆฌํ„ฐ๋Ÿด +ํ›„ ์‚ฝ์ž…echo0

๋˜๋Š”์ด 1 ์ƒ‰์ธ ๋ฒ„์ „ (103 + 1 ๋ฐ”์ดํŠธ)์„ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค.

for($a=range($p=1,$argn);$argn--;$d<$a[$p]?$a[$p--]/=$d+!$a[$p]+=$d:$p++)for($d=1;$a[$p]%++$d;);echo$p;

2

R , 123 ๋ฐ”์ดํŠธ

๊ฐ„๋‹จํ•œ ๊ตฌํ˜„. ์ด๋™ ํšŸ์ˆ˜๋ฅผ ์ž…๋ ฅ์œผ๋กœ ๋ฐ›์•„ ์œ„์น˜ p๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜๋กœ ์ œ๊ณต๋ฉ๋‹ˆ๋‹ค.

์‹œํ€€์Šค๋ฅผ ๋ฐ˜๋ณตํ•˜๊ณ  ๊ทœ์น™์— ๋”ฐ๋ผ ํฌ์ธํ„ฐ๋ฅผ ์•ž๋’ค๋กœ ์›€์ง์ž…๋‹ˆ๋‹ค. ์ถœ๋ ฅ์€ 0์„ ๊ธฐ์ค€์œผ๋กœํ•ฉ๋‹ˆ๋‹ค.

์ฐธ๊ณ  : ์ˆซ์ž x์˜ ๊ฐ€์žฅ ์ž‘์€ ์†Œ์ˆ˜๋ฅผ ์ฐพ๊ธฐ ์œ„ํ•ด 0์—์„œ x๊นŒ์ง€์˜ ๋ชจ๋“  ์ •์ˆ˜์— ๋Œ€ํ•œ x์˜ ๊ณ„์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ ๋ชจ๋“ˆ๋Ÿฌ์Šค๊ฐ€ 0 ์ธ ์ˆซ์ž๋ฅผ ์ถ”์ถœํ•˜๋ฉฐ, ํ•ญ์ƒ [0,1, ..., x]์ž…๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌํ•œ ์„ธ ๋ฒˆ์งธ ์ˆซ์ž๊ฐ€ x๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ x์˜ ๊ฐ€์žฅ ์ž‘์€ ์†Œ์ˆ˜์ž…๋‹ˆ๋‹ค.

p=function(l){w=0:l;v=w+1;j=1;for(i in w){y=v[j];x=w[!y%%w][3]
if(x%in%c(NA,y))j=j+1
else{v[j]=y/x;j=j-1;v[j]=v[j]+x}}
j-2}

์˜จ๋ผ์ธ์œผ๋กœ ์‚ฌ์šฉํ•ด๋ณด์‹ญ์‹œ์˜ค!


2

C (GCC), 152 (148) ๋ฐ”์ดํŠธ

์ถ•์†Œ

int f(int n){int*A=malloc(++n*4),p=0,i,q;for(i=0;i<n;i++)A[i]=i+2;for(i=1;i<n;i++){for(q=2;A[p]%q;q++);if(A[p++]>q){A[--p]/=q;A[--p]+=q;}}return p;}

์ผ๋ถ€ ์˜๊ฒฌ์œผ๋กœ ํ˜•์‹ํ™”

int f(int n) {
  int *A = malloc(++n * 4), p = 0, i, q;
  // Initialize array A
  for (i = 0; i < n; i++)
    A[i] = i + 2;
  // Do n step (remember n was incremented)
  for (i = 1; i < n; i++) {
    // Find smallest divisor
    for (q = 2; A[p] % q; q++)
      ;
    if (A[p++] > q) {
      A[--p] /= q;
      A[--p] += q;
    }
  }
  return p;
}

ํ…Œ์ŠคํŠธ๋ฅผ์œ„ํ•œ ์ฃผ์š” ๊ธฐ๋Šฅ

#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv) {
  if (argc != 2)
    return 2;
  int n = atoi(argv[1]);
  int p = f(n);
  printf("%d => %d\n", n, p);
  return 0;
}

๊ฐ ๋‹จ๊ณ„๋ฅผ ๋ณด์—ฌ์ฃผ๊ธฐ ์œ„ํ•ด

  1. f () ์•ˆ์— display () ์„ ์–ธ

    int f(int n) {
      int *A = malloc(++n * 4), p = 0, i, q;
      void display(void) {
        for (int i=0; i < p; i++) {
          printf(" %d", A[i]);
        }
        printf(" \033[1;31m%d\033[m", A[p]);
        if (p+1 < n)
          printf(" %d", A[p+1]);
        printf("\n");
      }
      ...
  2. ํ†ตํ™” ํ‘œ์‹œ ()

      A[i] = i + 2;
    display();
  3. ํ†ตํ™” ํ‘œ์‹œ ()

      }
      display();
    }

A๋ฅผ ๋ฐฐ์—ด๋กœ ์„ ์–ธํ•˜๊ณ  ๊ฐ€๋Šฅํ•œ ๊ฒฝ์šฐ ๋ฃจํ”„ ์ „์— ๋ฃจํ”„ ์ œ์–ด๋ฅผ ์ดˆ๊ธฐํ™”ํ•˜์—ฌ ์ผ๋ถ€ ๋ฐ”์ดํŠธ ๋ฅผ ์ค„์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค .
Monica Monica ๋ณต์›

1

ํด๋กœ์ €, 185 ๋ฐ”์ดํŠธ

#(loop[[n p][(vec(range 2 1e3))0]i %](if(= i 0)p(recur(if-let[q(first(for[i(range 2(n p)):when(=(mod(n p)i)0)]i))][(assoc n p(/(n p)q)(dec p)(+(n(dec p))q))(dec p)][n(inc p)])(dec i))))

"์ฃผ"๋ฅผ ํŽธ์ง‘ํ•˜๋Š” ๊ฒƒ์€ Clojure์—์„œ ์ด์ƒ์ ์ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋” ํฐ ์ž…๋ ฅ์„ ์œ„ํ•ด์„œ๋Š” ์ง€์ˆ˜๋ฅผ ๋Š˜๋ ค์•ผํ•ฉ๋‹ˆ๋‹ค.


์—์„œ ํŒจํ„ด ์ผ์น˜๋ฅผ ์‚ฌ์šฉํ•œ ์ด์œ ๋Š” ๋ฌด์—‡ loop์ž…๋‹ˆ๊นŒ? ๊ทธ๊ฒƒ์—†์ด ๋ช‡ ๋ฐ”์ดํŠธ๋ฅผ ์žƒ์„ ์ˆ˜ ์žˆ์–ด์•ผํ•ฉ๋‹ˆ๋‹ค.
clismique

๋˜ํ•œ first์‚ฌ๋ฌผ์„ some์ง„์ˆ  ๋กœ ๋ณ€๊ฒฝํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค .
clismique

ํŒจํ„ด ์ผ์น˜๊ฐ€ ์—†์œผ๋ฉด recur๊ฐ if-let๋ถ„๊ธฐ ๋งˆ๋‹ค ํ•˜๋‚˜์”ฉ ๋‘ ๋ฒˆ ๋ฐ˜๋ณตํ•ด์•ผํ–ˆ์Šต๋‹ˆ๋‹ค . ๋˜ํ•œ (dec i)๋ณต์ œ๋ฉ๋‹ˆ๋‹ค. ์šฐ๋ฆฌ๊ฐ€ ์ˆซ์ž๋ฅผ ๋‹ค๋ฃฐ ๋•Œ some์‚ฌ์šฉํ•  ์ˆ˜์žˆ๋Š” ์ˆ ์–ด๊ฐ€ ํ•„์š” +ํ•˜์ง€๋งŒ ์ด๊ฒƒ์€ 1 ์ž๋ณด๋‹ค ๊น๋‹ˆ๋‹ค first. CMIIW
NikoNyrh

1

์ž๋ฐ” 8, 138135 ๋ฐ”์ดํŠธ

n->{int a[]=new int[++n],s=0,p=0,j=0;for(;j<n;a[j++]=j+1);for(;++s<n;p++)for(j=1;++j<a[p];)if(a[p]%j<1){a[p--]/=j;a[p--]+=j;}return p;}

์„ค๋ช…:

์—ฌ๊ธฐ์—์„œ ์‹œ๋„ํ•˜์‹ญ์‹œ์˜ค.

n->{                     // Method with integer as both parameter and return-type
  int a[]=new int[++n],  //  Integer-array with a length of `n+1`
      s=0,               //  Steps-counter (starting at 0)
      p=0,               //  Current position (starting at 0)
      j=0;               //  Index integer (starting at 0)
  for(;j<n;              //  Loop (1) from 0 to the input (inclusive due to `++n` above)
    a[j++]=j+1           //   And fill the array with 2 through `n+2`
  );                     //  End of loop (1)
  for(;++s<n;            //  Loop (2) `n` amount of steps:
      p++)               //    And after every iteration: increase position `p` by 1
    for(j=1;             //   Reset `j` to 1
        ++j<a[p];)       //   Inner loop (3) from 2 to `a[p]` (the current item)
      if(a[p]%j<1){      //    If the current item is divisible by `j`:
        a[p--]/=j;       //     Divide the current item by `j`
        a[p--]+=j;}      //     And increase the previous item by `j`
                         //     And set position `p` two steps back (with both `p--`)
                         //   End of inner loop (3) (implicit / single-line body)
                         //  End of loop (2) (implicit / single-line body)
  return p;              //  Return the resulting position `p`
}                        // End of method

1

Clojure์—์„œ, 198 (193) 191 ๋ฐ”์ดํŠธ

์ด ๊ณจํ”„๋Š” ์‹ฌํ•˜๊ฒŒ ๊ณจํ”„๋ฅผ ์น  ํ•„์š”๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค ...

#(loop[i(vec(range 2(+ % 9)))c 0 p 0](if(= % c)p(let[d(dec p)u(i p)f(some(fn[n](if(=(mod u n)0)n))(range 2(inc u)))e(= u f)](recur(if e i(assoc i d(+(i d)f)p(/ u f)))(inc c)(if e(inc p)d)))))

๊ณจํ”„ 1 :๋กœ ๋ณ€๊ฒฝ (first(filter ...))ํ•˜์—ฌ 5 ๋ฐ”์ดํŠธ ์ €์žฅ(some ...)

Golf 2 :๋กœ ๋ณ€๊ฒฝ (zero? ...)ํ•˜์—ฌ 2 ๋ฐ”์ดํŠธ ์ €์žฅ(= ... 0)


์šฉ๋ฒ•:

(#(...) 10000) => 512

Ungolfed ์ฝ”๋“œ :

(defn prime-ant [n]
  (loop [counter 0
         pos 0
         items (vec (range 2 (+ n 9)))]
    (if (= n counter) pos
      (let [cur-item (nth items pos)
            prime-factor
            (some #(if (zero? (mod cur-item %)) %)
              (range 2 (inc cur-item)))
            equals? (= cur-item prime-factor)]
        (recur
          (inc counter)
          (if equals? (inc pos) (dec pos))
          (if equals? items
            (assoc items
              (dec pos) (+ (items (dec pos)) prime-factor)
              pos (/ cur-item prime-factor))))))))
๋‹น์‚ฌ ์‚ฌ์ดํŠธ๋ฅผ ์‚ฌ์šฉํ•จ๊ณผ ๋™์‹œ์— ๋‹น์‚ฌ์˜ ์ฟ ํ‚ค ์ •์ฑ…๊ณผ ๊ฐœ์ธ์ •๋ณด ๋ณดํ˜ธ์ •์ฑ…์„ ์ฝ๊ณ  ์ดํ•ดํ•˜์˜€์Œ์„ ์ธ์ •ํ•˜๋Š” ๊ฒƒ์œผ๋กœ ๊ฐ„์ฃผํ•ฉ๋‹ˆ๋‹ค.
Licensed under cc by-sa 3.0 with attribution required.