๐Ÿง ์—๋ผํ† ์Šคํ…Œ๋„ค์Šค์˜ ์ฒด   ํ•จ์ˆ˜

def decimal(num):
    for i in range(2, int(num**0.5) + 1):
        if num % i == 0:
            return False
    return Trueโ€‹
for i in range(2, 100):
    if decimal(i):
        print(i, end = " ")โ€‹โ€‹


์œ„์˜ ๊ณผ์ •์„ ํ†ตํ•ด ๊ธฐ์กด์˜ ๋ฆฌ์ŠคํŠธ์— ๋ˆ„์ ํ•˜์—ฌ ์ €์žฅํ•˜๋Š” ๋ฐฉ์‹๋ณด๋‹ค ๋”์šฑ ์งง์€ ์‹œ๊ฐ„๋ณต์žก๋„๋ฅผ ๊ฐ–๊ณ  ์†Œ์ˆ˜๋ฅผ ๋„์ถœํ•ด ๋‚ผ ์ˆ˜ ์žˆ๋‹ค.

 

๐Ÿง ํšŒ๋ฌธ ( Palindrome )

ํšŒ๋ฌธ(ๅ›žๆ–‡) ๋˜๋Š” ํŒฐ๋ฆฐ๋“œ๋กฌ(palindrome)์€ ๊ฑฐ๊พธ๋กœ ์ฝ์–ด๋„ ์ œ๋Œ€๋กœ ์ฝ๋Š” ๊ฒƒ๊ณผ ๊ฐ™์€ ๋ฌธ์žฅ์ด๋‚˜ ๋‚ฑ๋ง, ์ˆซ์ž, ๋ฌธ์ž์—ด(sequence of characters) ๋“ฑ์ด๋‹ค. ๋ณดํ†ต ๋‚ฑ๋ง ์‚ฌ์ด์— ์žˆ๋Š” ๋„์–ด์“ฐ๊ธฐ๋‚˜ ๋ฌธ์žฅ ๋ถ€ํ˜ธ๋Š” ๋ฌด์‹œํ•œ๋‹ค.

์ด๋Ÿฐ ํšŒ๋ฌธ์— ๋Œ€ํ•œ ๊ตฌํ˜„์„ ํŒŒ์ด์ฌ์€ ๋‹ค๋ฅธ ์–ธ์–ด์™€ ๋‹ค๋ฅด๊ฒŒ ๊ฐ„๋‹จํ•˜๊ฒŒ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ์ ์—์„œ ๋‹จ์—ฐ ํŒŒ์ด์ฌ์˜ ๋งค๋ ฅ์ด ๋‹๋ณด์ธ๋‹ค.
๋‹ค์Œ๊ณผ ๊ฐ™์ด ํšŒ๋ฌธ์„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค.

[์ˆซ์ž์ธ ๊ฒฝ์šฐ ํšŒ๋ฌธ์ธ์ง€ ํ™•์ธํ•˜๋Š” ๋ฒ•]
a, b = map(int,input().split())  

# a~b๋ฒ”์œ„ ์‚ฌ์ด ํšŒ๋ฌธ ๋ชจ๋‘ ๊ตฌํ•˜๊ธฐ
palindrome = [i for i in range(a,b+1) if str(i) == str(i)[::-1]]

 

[๋ฌธ์ž์ธ ๊ฒฝ์šฐ ํšŒ๋ฌธ์ธ์ง€ ํ™•์ธํ•˜๋Š” ๋ฒ•]
string = input()

if string == string[::-1]:
    print("palindrome")โ€‹

 

# a,b=map(int,input().split())
# print('%0.9f'%(a/b))  // ์ ˆ๋Œ€,์ƒ๋Œ€์˜ค์ฐจ๋Š” ์†Œ์ˆ˜์  9๋ฒˆ์งธ ์ž๋ฆฌ(0.1e-9)๊นŒ์ง€ ํ—ˆ์šฉ

 

๐Ÿง ์ ˆ๋Œ€์˜ค์ฐจ, ์ƒ๋Œ€์˜ค์ฐจ์˜  ํ‘œํ˜„ 

๋ฐฑ์ค€์„ ํ’€๋‹ค๋ณด๋ฉด ์œ„๋กœ ๊ฐˆ์ˆ˜๋ก ์ˆ˜ํ•™, ๊ธฐํ•˜๋ฌธ์ œ์˜ ๊ฒฝ์šฐ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋‚ด์šฉ์„ ๋ณด๋Š” ๊ฒฝ์šฐ๊ฐ€ ์ข…์ข… ์žˆ๋‹ค.
์ด์— ๋Œ€ํ•ด ์–ด๋–ค ๋ฐฉ์‹์œผ๋กœ ์ถœ๋ ฅ์„ ํ•ด์•ผํ•  ์ง€ ๊ฐ‘์ž๊ธฐ ๋ง‰ํž ์ˆ˜ ์žˆ๊ธฐ์— ์ด๋ฒˆ๊ธฐํšŒ์— ์งš๊ณ  ๋„˜์–ด๊ฐ€๊ณ ์ž ํ•œ๋‹ค.



๋‹ค๋งŒ, 10^-9 ์ดํ•˜์˜ ์˜ค์ฐจ๋ฅผ ํ—ˆ์šฉํ•œ๋‹ค๋Š” ๋ง์ด ๊ผญ ์†Œ์ˆ˜ 9๋ฒˆ์งธ์ž๋ฆฌ๊นŒ์ง€๋งŒ ์ถœ๋ ฅํ•˜๋ผ๋Š” ๊ฒƒ์€ ์•„๋‹ˆ๋‹ค.
์˜ˆ๋กœ  ๋ฐฑ์ค€1008๋ฒˆ์„ ์˜ˆ๋กœ ๋“ค๊ฒ ๋‹ค. 

์†Œ์ˆ˜์  9๋ฒˆ์งธ์ž๋ฆฌ ๋ณด์—ฌ์ฃผ๋Š” ๋ฐฉ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.
a, b = map(float,input().split()) 
print('%0.9f'%(a/b)) // ์ ˆ๋Œ€,์ƒ๋Œ€์˜ค์ฐจ๋Š” ์†Œ์ˆ˜์  9๋ฒˆ์งธ ์ž๋ฆฌ(0.1e-9)๊นŒ์ง€ ํ—ˆ์šฉโ€‹โ€‹

์†Œ์ˆซ์  ์•ž์˜ ์ˆซ์ž๋Š” ์ „์ฒด ๊ธธ์ด๋ฅผ ์ •ํ•œ ๋ฌธ์ž์—ด ๊ณต๊ฐ„ ์ˆ˜๋ฅผ ์˜๋ฏธํ•จ( 0์€ ์ •ํ•˜์ง€ ์•Š์Œ์„ ์˜๋ฏธ )
์†Œ์ˆซ์ ('.')๋’ค์˜ ์ˆซ์ž9๋Š” ์†Œ์ˆซ์  ๋’ค์— ๋‚˜์˜ฌ ์ˆซ์ž์˜ ๊ฐœ์ˆ˜๋ฅผ ์˜๋ฏธํ•จ

<์ž์ฃผ์“ฐ๋Š” ๋ฌธ์ž์—ด ํฌ๋งท ์ฝ”๋“œ ์ข…๋ฅ˜ >
%s: ๋ฌธ์ž์—ด(string)
%c: ๋ฌธ์ž 1๊ฐœ (character)
%d:์ •์ˆ˜(integer) 
%f:๋ถ€๋™์†Œ์ˆ˜(floating- point)                   

%%: ๋ฌธ์ž %์ž์ฒดโ€‹

 

 

 

 

 

๐Ÿง ๋ฐฑ์ค€ 1990 (์†Œ์ˆ˜์ธ ํšŒ๋ฌธ)    Gold V 




๐Ÿคซ  solution_1990(์‹œ๊ฐ„์ดˆ๊ณผ)

import math, sys
input = sys.stdin.readline
a, b = map(int, input().split())

dec = [i for i in range(b+1)]
dec_first = []
for i in range(2, int(b**0.5) + 1):
    if i in dec:
        dec_first.append(i)
    dec = [j for j in dec if j%i != 0]
decimal = dec_first + dec

ans = []
def palindrome(num):
    string_num = str(num)
    num_len = len(string_num)
    if string_num[:num_len // 2] == string_num[math.ceil(num_len / 2):][::-1]:
        if num in decimal:
            ans.append(num)

for i in range(a, b+1):
    palindrome(i)
ans.append(-1)
print(*ans, sep = "\n")

 

๐Ÿคซ  solution_1990

a, b = map(int,input().split())

def decimal(num):
    for i in range(2, int(num**0.5) + 1):
        if num % i == 0:
            return False
    return True


#10,000,000์ด์ƒ์ธ ํŒฐ๋ฆฐ๋“œ๋กฌ์ˆ˜๋Š” ์กด์žฌ X
if b > 10000000 :
    b=10000000

palindrome = [i for i in range(a,b+1) if str(i) == str(i)[::-1]]
for i in palindrome:
    if decimal(i):
        print(i)
print(-1)

 

 

 

 

๐Ÿง ๋ฐฑ์ค€ 15927 (ํšŒ๋ฌธ์€ ํšŒ๋ฌธ์ด ์•„๋‹ˆ์•ผ!)    Gold V 




๐Ÿคซ  Algorithm 

1) ๋ฌธ์ž์—ด ์ „์ฒด๊ฐ€ ํšŒ๋ฌธ์ด ์•„๋‹ˆ๋ฉด ๋‹ต์€ ๋ฌธ์ž์—ด์˜ ๊ธธ์ด์ด๋‹ค.
2) ๋ฌธ์ž์—ด ์ „์ฒด๊ฐ€ ํšŒ๋ฌธ์ผ ๋•Œ,
 i) ๋ฌธ์ž์—ด ์ „์ฒด๊ฐ€ ๋ชจ๋‘ ๊ฐ™์€ ๋ฌธ์ž์ผ ๋•Œ ํŒฐ๋ฆฐ๋“œ๋กฌ์ด ์•„๋‹Œ ๋ถ€๋ถ„ ๋ฌธ์ž์—ด์ด ์กด์žฌํ•˜์ง€ ์•Š๊ธฐ์— ๋‹ต์€ -1์ด๋‹ค.
 ii) ์ฒ˜์Œ ๋˜๋Š” ๋์˜ ๋ฌธ์ž ํ•˜๋‚˜๋งŒ ์ œ์™ธํ•œ ๋ฌธ์ž์—ด์€ ํŒฐ๋ฆฐ๋“œ๋กฌ์ด ์•„๋‹ˆ๊ธฐ์— ๋‹ต์€ (์›๋ž˜ ๋ฌธ์ž์—ด์˜ ๊ธธ์ด - 1)์ด๋‹ค.



๐Ÿคซ  solution_15927

string = input()

ans = 0
if string == string[::-1]:
    if string[:len(string) // 2 + 1] == string[:len(string) // 2 + 1][::-1]:
        ans = -1
    else:
        ans = len(string) - 1
else:
    ans = len(string)

print(ans)

 

 

 

 

๐Ÿง ๋ฐฑ์ค€ 11664 (CCW, ์™ธ์ )    Gold V 





๐Ÿคซ  Algorithm 

# ์  a๋ฅผ ์„ ๋ถ„์˜ ์™ผ์ชฝ์— ์žˆ๋Š” ์ , ์  b๋ฅผ ์„ ๋ถ„์˜ ์˜ค๋ฅธ์ชฝ์— ์žˆ๋Š” ์ ์ด๋ผ ํ•˜์ž.
# ์  a์™€ ์  b์˜ ์ค‘๊ฐ„์  m์„ ๊ตฌํ•œ๋‹ค.

# l = ์  a์™€ ์  c์˜ ๊ฑฐ๋ฆฌ
# r = ์  b์™€ ์  c์˜ ๊ฑฐ๋ฆฌ
# h = ์  m๊ณผ ์  c์˜ ๊ฑฐ๋ฆฌ

# ๋งŒ์•ฝ h๊ฐ€ ํ˜„์žฌ ์กด์žฌํ•˜๋Š” ์ตœ์†Œ๊ฐ’ ans๋ณด๋‹ค ์ž‘๋‹ค๋ฉด, ans๋ฅผ h๋กœ ๊ฐฑ์‹ ํ•ด์ค๋‹ˆ๋‹ค.
# ๋งŒ์•ฝ l์ด r๋ณด๋‹ค ํฌ๋‹ค๋ฉด, c๊ฐ€ a๋ณด๋‹ค b์— ๋” ๊ฐ€๊น๊ฒŒ ์žˆ๋‹ค๋Š” ๋œป์ด๋ฏ€๋กœ ์  a๋ฅผ ์  m์œผ๋กœ ๋ฐ”๊ฟ”์ค€๋‹ค.
# (์ด๋ถ„ํƒ์ƒ‰์„ ์ง„ํ–‰ํ•ด์•ผ ํ•˜๋ฏ€๋กœ ๋” ๊ฐ€๊นŒ์šด ์ชฝ์œผ๋กœ ๋ฒ”์œ„๋ฅผ ์ขํ˜€์ค˜์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ.)
# ๋ฐ˜๋Œ€๋กœ r์ด l๋ณด๋‹ค ํฌ๋‹ค๋ฉด c๊ฐ€ b๋ณด๋‹ค a์— ๋” ๊ฐ€๊น๊ฒŒ ์žˆ๋‹ค๋Š” ๋œป์ด๋ฏ€๋กœ ์  b๋ฅผ ์  m์œผ๋กœ ๋ฐ”๊ฟ”์ค€๋‹ค.




๐Ÿคซ  solution_11664

ax,ay,az,bx,by,bz,cx,cy,cz = map(int,input().split())

ans = float('inf')

while True:
    mx,my,mz = (ax+bx)/2,(ay+by)/2,(az+bz)/2
    l = ((ax-cx)**2+(ay-cy)**2+(az-cz)**2)**0.5
    h = ((mx-cx)**2+(my-cy)**2+(mz-cz)**2)**0.5
    r = ((bx-cx)**2+(by-cy)**2+(bz-cz)**2)**0.5

    if abs(ans-h) <= 1e-6:
        print('%0.10f'%ans)
        exit()
    if h < ans:
        ans = h
    if l > r:
        ax,ay,az = mx,my,mz
    else:
        bx,by,bz = mx,my,mz

 

+ Recent posts