BOJ/๐Ÿฅˆ

โ˜…Math & Geometry Intermediate I - 13 Solvedโ˜…

metamong 2022. 11. 22.

โ˜… 1676 ํŒฉํ† ๋ฆฌ์–ผ 0์˜ ๊ฐœ์ˆ˜ โ˜…

 

๐Ÿง˜๐Ÿผ‍โ™‚๏ธ ๋’ค์—์„œ๋ถ€ํ„ฐ ๊ฑฐ๊พธ๋กœ ์ผ์ผ์ด 0์˜ ๊ฐœ์ˆ˜๋ฅผ ๋ฌธ์ œ๋Œ€๋กœ ์ฐพ๋Š” brute-force

N = int(input())
fac = 1
for i in range(N, 0, -1):
    fac *= i

cnt = 0
for num in str(fac)[::-1]:
    if num == '0':
        cnt += 1   
    else:
        break
print(cnt)

 

๐Ÿง˜๐Ÿผ‍โ™‚๏ธ ๊ทธ๋Ÿฌ๋‚˜, ์ˆ˜ํ•™์ ์œผ๋กœ ์ ‘๊ทผํ•ด์„œ brute-force๊ฐ€ ์•„๋‹Œ ์ˆ˜ํ•™ ํ’€์ด๋กœ ์‹œ๊ฐ„์„ ๋” ๋‹จ์ถ•ํ•˜์ž๋ฉด,

 

๐Ÿง˜๐Ÿผ‍โ™‚๏ธ ํŒฉํ† ๋ฆฌ์–ผ ๊ฒฐ๊ณผ ๋์˜ 0์˜ ๊ฐœ์ˆ˜ → 10์œผ๋กœ ๋‚˜๋ˆ„์–ด์ง€๋Š” ํšŸ์ˆ˜์˜ ๊ฐœ์ˆ˜ → 5์™€ 2์˜ ๊ฐœ์ˆ˜ → 5์˜ ๊ฐœ์ˆ˜

โ‘  10์œผ๋กœ ๋‚˜๋ˆ„์–ด๋–จ์–ด์ง„๋‹ค๋ฉด ๋์— 0์ด 1๊ฐœ, 100์œผ๋กœ ๋‚˜๋ˆ„์–ด๋–จ์–ด์ง„๋‹ค๋ฉด ๋์— 0์ด 2๊ฐœ, ์ฆ‰ ๋์˜ 0์˜ ๊ฐœ์ˆ˜๋Š” 10์œผ๋กœ ๋‚˜๋ˆ„์–ด์ง€๋Š” ํšŸ์ˆ˜์˜ ๊ฐœ์ˆ˜

โ‘ก 10์€ 2*5๋กœ ๊ตฌ์„ฑ๋˜๋ฏ€๋กœ, 2์™€ 5๋ฅผ ์Œ์œผ๋กœ ํ•œ ๊ฐœ์ˆ˜๊ฐ€ ๋ช‡ ๊ฐœ์ธ์ง€๋ฅผ ๋œปํ•จ

โ‘ข 2๋Š” 5์— ๋น„ํ•ด ๋ฌด์ˆ˜ํžˆ ๋งŽ์œผ๋ฏ€๋กœ ์šฐ๋ฆฌ๋Š” 5์˜ ๊ฐœ์ˆ˜๋งŒ ๊ตฌํ•˜๋ฉด ๋จ

โ‘ฃ ์ฆ‰, 5๋ฅผ ๊ณฑํ•˜๋ฉด ๋์— 0์ด 1๊ฐœ ์ฆ๊ฐ€, 10์„ ๊ณฑํ•˜๋ฉด 0์ด 2๊ฐœ ์ฆ๊ฐ€, ~ ๊ทธ๋Ÿฌ๋‚˜ 5์˜ ์ œ๊ณฑ์ˆ˜์˜ ๋ฐฐ์ˆ˜ - 25์˜ ๋ฐฐ์ˆ˜, 125์˜ ๋ฐฐ์ˆ˜ ๋“ฑ๋“ฑ์„ ๊ณฑํ•˜๋ฉด, ๊ณฑํ•  ๋•Œ 5๊ฐ€ ๊ฐ๊ฐ 2๋ฒˆ, 3๋ฒˆ์ด๋‚˜ ๊ณฑํ•ด์ง€๋ฏ€๋กœ 5์˜ ์ œ๊ณฑ์ˆ˜ ๋ฐฐ์ˆ˜๋งŒ ์ฃผ์˜ (625๋ถ€ํ„ฐ๋Š” ๋ฌธ์ œ ์กฐ๊ฑด N <= 500์— ์˜ํ•ด ์ƒ๊ด€์—†์Œ)

 

๐Ÿง˜๐Ÿผ‍โ™‚๏ธ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํ๋ฆ„

โ‘  5๋กœ ๋‚˜๋ˆˆ ๋ชซ ๋”ํ•˜๊ธฐ (๋”ฑ 5๊ฐ€ 1๋ฒˆ ๊ณฑํ•ด์ง€๋Š” ํšŸ์ˆ˜ ์นด์šดํŠธ)

โ‘ก 25๋กœ ๋‚˜๋ˆˆ ๋ชซ ๋”ํ•˜๊ธฐ (25 ๋ฐฐ์ˆ˜๋Š” 5๊ฐ€ ์ตœ์†Œ 2๋ฒˆ ์ด์ƒ ์žˆ๊ณ , ์œ„ โ‘ ์—์„œ 5์นด์šดํŠธ ํ–ˆ์œผ๋ฏ€๋กœ 25๊ฐ€ 1๋ฒˆ ๊ณฑํ•ด์ง€๋Š” ํšŸ์ˆ˜๋งŒ ์นด์šดํŠธ)

โ‘ข 125๋กœ ๋‚˜๋ˆˆ ๋ชซ ๋”ํ•˜๊ธฐ (๋งˆ์ฐฌ๊ฐ€์ง€๋กœ 125๊ฐ€ 1๋ฒˆ ๊ณฑํ•ด์ง€๋Š” ํšŸ์ˆ˜๋งŒ ์นด์šดํŠธ)

โ‘ฃ 625๋กœ ๋‚˜๋ˆˆ ๋ชซ ๋”ํ•˜๊ธฐ ~~ ๋“ฑ๋“ฑ (๋ฌธ์ œ์—์„  500๊นŒ์ง€์ด๋ฏ€๋กœ ์ ์šฉ x)

N=int(input())
print(N//5+N//25+N//125)

 

๐Ÿง˜๐Ÿผ‍โ™‚๏ธ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํ๋ฆ„ ์ผ๋ฐ˜ํ™”

→ 5 - 25 - 125 - 625 ~ 5์˜ ์ œ๊ณฑ์ˆ˜๊ฐ€ ์ด์ „ ์ œ๊ณฑ์ˆ˜์˜ 5๋ฐฐ์ธ ์„ฑ์งˆ์„ ์ด์šฉํ•œ๋‹ค

ex) ์˜ˆ๋ฅผ ๋“ค์–ด 5๋กœ ๋‚˜๋ˆˆ ๋ชซ์ด 0์ด ์•„๋‹ˆ๋ผ๋ฉด, ํ•ด๋‹น ๋ชซ์— 5๋ฅผ ๋˜ ๋‚˜๋ˆˆ ๋ชซ์ด 0์•„๋‹ ๊ฒฝ์šฐ 25์ด์ƒ์ž„์„ ๋œปํ•œ๋‹ค. ์ด ์„ฑ์งˆ์„ ์ด์šฉํ•ด ์•„๋ž˜์™€ ๊ฐ™์ด while๋ฌธ ์ž‘์„ฑ ๊ฐ€๋Šฅ

N=int(input())
cnt=0
while N>4:
    cnt+=N//5
    N//=5
print(cnt)

โ˜… 24313 ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ˆ˜์—… - ์ ๊ทผ์  ํ‘œ๊ธฐ 1 โ˜…

 

a1, a0 = map(int, input().split())
c = int(input())
n0 = int(input())

if a1 == c:    
    if -100<= a0 <= 0:
        print(1)
    
    else:
        print(0)

elif a1 < c:
    if n0 >= (a0/(c-a1)):
        print(1)

    else:
        print(0)

else:
    print(0)

 

๐Ÿง˜๐Ÿผ‍โ™‚๏ธ ํŠน์ •์ƒํ™ฉ์—์„œ O-ํ‘œ๊ธฐ๋ฒ•์„ ๋งŒ์กฑํ•˜๋Š” ์ง€ ๋ฌป๋Š” ๋ฌธ์ œ์ด๋‹ค.

โ‘  f(n) = a1n + a0 (0<=|ai|<=100)

โ‘ก g(n) = n

 

๐Ÿง˜๐Ÿผ‍โ™‚๏ธ a1,a0,c๊ฐ€ ๋ชจ๋‘ ์ฃผ์–ด์ง„ ์ƒํƒœ์—์„œ ๋ถ€๋“ฑ์‹์„ ์ •๋ฆฌํ•˜๋ฉด n(c-a1)>=a0

 

๐Ÿง˜๐Ÿผ‍โ™‚๏ธ

โ‘  c = a1 → a0<=0์ผ ๊ฒฝ์šฐ O-ํ‘œ๊ธฐ๋ฒ•์„ ๋งŒ์กฑํ•ด์„œ 1 ์•„๋‹ˆ๋ฉด 0

 

โ‘ก c > a1 

→ ๋ถ€๋“ฑํ˜ธ๋ฅผ ์ •๋ฆฌํ•˜๋ฉด n<=(a0/(c-a1))

→ n<=n0๋ฅผ ๋งŒ์กฑํ•ด์•ผ ํ•˜๋ฏ€๋กœ (a0/(c-a1))>=n0์ด๋ฉด O-ํ‘œ๊ธฐ๋ฒ•์„ ๋งŒ์กฑํ•ด์„œ 1, ์•„๋‹ˆ๋ฉด 0

 

โ‘ข c < a1

→ ์œ„ โ‘ก์™€ ๋ถ€๋“ฑํ˜ธ๊ฐ€ ๋ฐ˜๋Œ€๋ฐฉํ–ฅ์œผ๋กœ ๋˜๋ฏ€๋กœ n0๋ณด๋‹ค ํฐ ๋ชจ๋“  n์ด ๋งŒ์กฑํ•  ์ˆ˜ ์—†์Œ. ๋”ฐ๋ผ์„œ ์˜ค๋กœ์ง€ 0๋งŒ ๊ฐ€๋Šฅ


โ˜… 24314 ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ˆ˜์—… - ์ ๊ทผ์  ํ‘œ๊ธฐ 2 โ˜…

 

a1,a0=map(int, input().split())
c=int(input())
n0=int(input())

if a1==c:
    if a0>=0:print(1)
    else:print(0)

elif a1>c:
    if n0>=(a0/(c-a1)):print(1)
    else:print(0)

else:print(0)

 

โ€ป ์œ„ 24313 ๋ฌธ์ œ์™€ ๋ถ€๋“ฑํ˜ธ ๋ฐฉํ–ฅ๋งŒ ๋ฐ”๋€œ โ€ป


โ˜… 1193 ๋ถ„์ˆ˜์ฐพ๊ธฐ โ˜…

 

X=int(input())
num=(((8*X+1)**(1/2)-1)/2)
if num==int(num):
    n = int(num -1)
else:
    n = int(num)
order=X-((n)*(n+1)//2)
if (n+2)%2==0:
    print(str(n+2-order)+'/'+str(order))
else:
    print(str(order)+'/'+str(n+2-order))

 

๐Ÿง˜๐Ÿผ‍โ™‚๏ธ

โ‘  ๋Œ€๊ฐ์„  ๋ฐฉํ–ฅ์œผ๋กœ ๋ถ„์ˆ˜ + ๋ถ„์ž์˜ ํ•ฉ์ด 1 → 2 → 3 → 4 ํ˜•ํƒœ๋กœ ์ปค์ง€๋Š” ๊ทœ์น™์„ ์‚ฌ์šฉ

โ‘ก ์•ž์„  ๋ชจ๋“  ๋Œ€๊ฐ์„  ๋ฐฉํ–ฅ์˜ ๊ฐœ์ˆ˜๋ฅผ n์ด๋ผ ํ•˜๋ฉด

 

→ if๋ฌธ์œผ๋กœ num์œผ๋กœ ์œ„ ๋ถ€๋“ฑ์‹์˜ n ๊ฐ’์„ ๊ตฌํ•œ๋‹ค.

 

๐Ÿง˜๐Ÿผ‍โ™‚๏ธ๊ทธ๋ ‡๋‹ค๋ฉด ๋Œ€๊ฐ์„  ๋ฐฉํ–ฅ์˜ ์ผ์ •ํ•œ ๋ถ„์ž+๋ถ„๋ชจ์˜ ํ•ฉ์€ n+2

 

โ‘ข ๋ถ„์ž+๋ถ„๋ชจ์˜ ํ•ฉ์ด ์ง์ˆ˜์ธ์ง€ ํ™€์ˆ˜์ธ์ง€์— ๋”ฐ๋ผ ๊ฒฐ๊ณผ ์ถœ๋ ฅํ•˜๋ฉด ๋!

 

๐Ÿง˜๐Ÿผ‍โ™‚๏ธ๋‹ค๋ฅธ ํ’€์ด

X=int(input())
num_of_diagonal_lines=1
cum_num_of_diagonal_lines=1
before_cum_num_of_diagonal_lines=0
while cum_num_of_diagonal_lines < X:
    before_cum_num_of_diagonal_lines=cum_num_of_diagonal_lines
    cum_num_of_diagonal_lines+=(num_of_diagonal_lines+1)
    num_of_diagonal_lines+=1
order = X -before_cum_num_of_diagonal_lines
total=num_of_diagonal_lines+1
if total%2==1:
    print(f'{order}/{total-order}')
else:
    print(f'{total-order}/{order}')

 

→ ์ง์ ‘ ๋Œ€๊ฐ์„  ๊ฐœ์ˆ˜๋ฅผ ๋ˆ„์ ์œผ๋กœ ๋”ํ•œ ๊ฒƒ๊ณผ / ํ˜„์žฌ ๋Œ€๊ฐ์„ ์˜ ๊ฐœ์ˆ˜๋ฅผ while๋ฌธ์œผ๋กœ ์—…๋ฐ์ดํŠธํ•˜๋ฉฐ ์ตœ์ข…์ ์œผ๋กœ order์™€ total์„ ๊ตฌํ•˜๊ณ  ๋ฐ”๋กœ ์ถœ๋ ฅ!

๋ˆ„์ ์œผ๋กœ ๋”ํ•ด๊ฐ€๋Š” add upํ•˜๋Š” ์—ฌ๋Ÿฌ ๋ณ€์ˆ˜๋ฅผ while๋ฌธ์œผ๋กœ updateํ•œ๋‹ค๋Š” ์  ์ฃผ์˜!


โ˜… 13345 Completing the Square โ˜…

 

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

d1,d2,d3=(ax-bx)**2+(ay-by)**2,(ax-cx)**2+(ay-cy)**2,(bx-cx)**2+(by-cy)**2

if d1>d2: #max d1
    print(ax+bx-cx,ay+by-cy)
elif d2>d3: #max d2
    print(ax+cx-bx,ay+cy-by)
else: #max d3
    print(cx+bx-ax,cy+by-ay)

 

๐Ÿง˜๐Ÿผ‍โ™‚๏ธ ์ •์‚ฌ๊ฐํ˜•์˜ ์„ธ ๊ผญ์ง€์ ์˜ ์ขŒํ‘œ๊ฐ€ ์ฃผ์–ด์ง„ ์ƒํƒœ์—์„œ ๋‚˜๋จธ์ง€ ๊ผญ์ง€์ ์˜ x, y ์ถœ๋ ฅ ๋ฌธ์ œ. ์„ธ ๊ผญ์ง€์ ๊ฐ„์˜ ๊ฑฐ๋ฆฌ๋ฅผ ๊ตฌํ•œ ํ›„, ์ตœ๋Œ€ ๊ฑฐ๋ฆฌ์— ์žˆ๋Š” ๋‘ ์ ์ด ์ •์‚ฌ๊ฐํ˜•์˜ ๋Œ€๊ฐ์„ ์„ ์ด๋ฃจ๋Š” ๋‘ ์ ์ด๋ฏ€๋กœ, ๋‘ ์ ์˜ ํ•ฉ์— ๋‚˜๋จธ์ง€ ๊ผญ์ง€์ ์„ ๋บ€ ์ขŒํ‘œ๊ฐ€ ์ถœ๋ ฅํ•˜๊ณ ์ž ํ•˜๋Š” x, y

: ์ •์‚ฌ๊ฐํ˜•์˜ ์„ธ ๊ผญ์ง€์ ์˜ ์ขŒํ‘œ๋งŒ ์•Œ๋ฉด ๋‘ ๋Œ€๊ฐ์„ ์˜ ์ค‘์ ์€ ์ผ์น˜ํ•œ๋‹ค๋Š” ์„ฑ์งˆ์„ ์ด์šฉํ•ด ๋‚˜๋จธ์ง€ ํ•œ ๊ผญ์ง€์ ์˜ ์ขŒํ‘œ๋Š” ์œ„์™€ ๊ฐ™์ด ์•Œ ์ˆ˜ ์žˆ๋‹ค. 


โ˜… 15803 PLAYERJINAH'S BOTTLEGROUNDS โ˜…

coordinates=[]
for _  in range(3):
    x,y=map(int,input().split())
    coordinates.append((x,y))

one,two,three=coordinates[0],coordinates[1],coordinates[2]
if (two[0]!=one[0]) and (three[0]!=one[0]) and (two[0]!=three[0]):
    s1,s2,s3=(two[1]-one[1])/(two[0]-one[0]),(three[1]-one[1])/(three[0]-one[0]),(three[1]-two[1])/(three[0]-two[0])
    if s1==s2==s3:
        print('WHERE IS MY CHICKEN?')
    else:
        print('WINNER WINNER CHICKEN DINNER!')
else:
    a,b,c=one[0],two[0],three[0]
    if len(set([a,b,c])) == 1:
        print('WHERE IS MY CHICKEN?')
    else:
        print('WINNER WINNER CHICKEN DINNER!')

 

๐Ÿง˜๐Ÿผ‍โ™‚๏ธ ์„ธ ์ ์ด ํ•œ ์ง์„ ์„ ์ด๋ฃจ๋Š” ์ง€ ์•Œ์•„๋ณด๋Š” ์œ ํ˜•. A,B,C ์„ธ ์ ์ด ์žˆ๋‹ค๋ฉด A์™€ B๋ฅผ ์ž‡๋Š” ์ง์„ ์˜ ๊ธฐ์šธ๊ธฐ, B์™€ C๋ฅผ ์ž‡๋Š” ์ง์„ ์˜ ๊ธฐ์šธ๊ธฐ, A์™€ C๋ฅผ ์ž‡๋Š” ์ง์„ ์˜ ๊ธฐ์šธ๊ธฐ ์ด 3๊ฐœ์˜ ๊ธฐ์šธ๊ธฐ๊ฐ€ ๋ชจ๋‘ ๋™์ผํ•˜๋ฉด ํ•œ ์ง์„ . ๋™์ผํ•˜์ง€ ์•Š๋‹ค๋ฉด ํ•œ ์ง์„ ์— ์žˆ์ง€ ์•Š๋‹ค๊ณ  ๋งํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด ๋•Œ, ๊ธฐ์šธ๊ธฐ๋ฅผ ๊ตฌํ•  ๋•Œ ๋ถ„๋ชจ๊ฐ€ 0์ด ๋˜๋Š” ๊ฒฝ์šฐ๋งŒ ์ฃผ์˜. ๋ถ„๋ชจ๊ฐ€ 0์ด ๋  ๊ฒฝ์šฐ, ์ฆ‰ ์„ธ ์  ์ค‘ x์ขŒํ‘œ๊ฐ€ ๋™์ผํ•œ ์Œ์ด ์กด์žฌํ•  ๊ฒฝ์šฐ, ์„ธ ์ ์˜ x์ขŒํ‘œ๊ฐ€ ๋ชจ๋‘ ๋™์ผํ•œ ๊ฒฝ์šฐ๋งŒ ์ง์„ . ์•„๋‹Œ ๊ฒฝ์šฐ๋Š” ์ง์„  x


โ˜… 1358 ํ•˜ํ‚ค โ˜…

import sys
input=sys.stdin.readline

W,H,X,Y,P=map(int,input().split())
ans=0
for _ in range(P):
    x,y=map(int,input().split())
    if X<=x<=X+W and Y<=y<=Y+H:
        ans+=1
    else:
        #centers of circles each: (X,Y+H/2) (X+W,Y+H/2)
        if ((x-X)**2 + (y-(Y+(H/2)))**2)<=(H/2)**2:
            ans+=1
        else:
            if ((x-(X+W))**2 + (y-(Y+(H/2)))**2)<=(H/2)**2:
                ans+=1

print(ans)

 

๐Ÿง˜๐Ÿผ‍โ™‚๏ธ ์ฃผ์–ด์ง„ ์ ์ด ์ง์‚ฌ๊ฐํ˜•์— ์žˆ๋Š” ์ง€์˜ ์—ฌ๋ถ€๋Š” (x,y)์˜ x๊ฐ€ X์™€ X+W ์‚ฌ์ด, y๊ฐ€ Y์™€ Y+H ์‚ฌ์ด์— ์žˆ๋Š” ์ง€ ํ™•์ธ

 

๐Ÿง˜๐Ÿผ‍โ™‚๏ธ ์› ์•ˆ์— ์žˆ๋Š” ์ง€์˜ ์—ฌ๋ถ€๋Š” (x,y)๊ฐ€ ๊ฐ ์›์˜ ์ค‘์‹ฌ๊ณผ์˜ ๊ฑฐ๋ฆฌ๊ฐ€ ๋ฐ˜์ง€๋ฆ„ ์ดํ•˜์ธ์ง€ ํ™•์ธ


โ˜… 1064 ํ‰ํ–‰์‚ฌ๋ณ€ํ˜• โ˜…

 

import sys
xa,ya,xb,yb,xc,yc=map(int,input().split())
AB=((xb-xa)**2+(yb-ya)**2)**(1/2)
BC=((xb-xc)**2+(yb-yc)**2)**(1/2)
AC=((xc-xa)**2+(yc-ya)**2)**(1/2)
#check if 3 aligned in one line
if xa==xb==xc:
    print(-1)
    sys.exit()
elif ya==yb==yc:
    print(-1)
    sys.exit()
else:
    if xa==xb:
        slope1=0
    else:
        slope1=(ya-yb)/(xa-xb)
    if xc==xb:
        slope2=0
    else:
        slope2=(yc-yb)/(xc-xb)
    if slope1==slope2:
        print(-1)
        sys.exit()
    else:
        print(max(AB*2+BC*2,BC*2+AC*2,AB*2+AC*2)-min(AB*2+BC*2,BC*2+AC*2,AB*2+AC*2))

 

๐Ÿง˜๐Ÿผ‍โ™‚๏ธ ํ‰ํ–‰์‚ฌ๋ณ€ํ˜•์„ ์ด๋ฃจ์ง€ ์•Š๋Š” ๊ฒฝ์šฐ๋งŒ ์ƒ๊ฐํ•ด์ฃผ๋ฉด ๋œ๋‹ค. ์„ธ ์ ์ด ๋ชจ๋‘ ์ผ์ง์„ ์„ ์ด๋ฃจ๋Š” ๊ฒฝ์šฐ๋Š” ํ‰ํ–‰์‚ฌ๋ณ€ํ˜•์ด ๋  ์ˆ˜ ์—†๋‹ค. ์ด ๋•Œ ์„ธ ์ ์ด ๋ชจ๋‘ y์ถ•์— ์žˆ๋Š” ๊ฒฝ์šฐ / ๋ชจ๋‘ x์ถ•์— ์žˆ๋Š” ๊ฒฝ์šฐ / ํ•ด๋‹น ๋‘ ์ผ€์ด์Šค๊ฐ€ ์•„๋‹Œ ์ผ์ง์„ ์— ์žˆ๋Š” ๊ฒฝ์šฐ ๊ฐ๊ฐ ํŒ๋ณ„

 

๐Ÿง˜๐Ÿผ‍โ™‚๏ธ ์„ธ ์ ์ด ๋ชจ๋‘ ์ผ์ง์„ ์— ์žˆ์ง€ ์•Š๋‹ค๋ฉด ํ‰ํ–‰์‚ฌ๋ณ€ํ˜•์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ, ์„ธ ๊ฐœ์˜ ์ ์„ A,B,C๋ผ๊ณ  ํ–ˆ์„ ๋•Œ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š” ํ‰ํ–‰์‚ฌ๋ณ€ํ˜•์€ (1) AB,BC๋ฅผ ๋ณ€์œผ๋กœ / (2) AB, AC๋ฅผ ๋ณ€์œผ๋กœ / (3) BC,AC๋ฅผ ๋ณ€์œผ๋กœ ํ•˜๋Š” ์„ธ ๊ฐœ์˜ case, ์„ ๋ถ„ ๊ธธ์ด ๊ณต์‹์œผ๋กœ ๊ตฌํ•ด ์ตœ๋Œ“๊ฐ’, ์ตœ์†Ÿ๊ฐ’ ์ฐจ์ด ๋ฐ”๋กœ ์ถœ๋ ฅํ•˜๋ฉด ๋


โ˜… 1748 ์ˆ˜ ์ด์–ด ์“ฐ๊ธฐ 1 โ˜…

N=input()
l=len(N)
ans=0
start=9
for i in range(1,l):
    ans+=start*i
    start*=10
if l!=1:
    remain=int(N)-9*(int('1'*(l-1)))
    print(ans+remain*(l))
else:
    print(int(N))

 

๐Ÿง˜๐Ÿผ‍โ™‚๏ธ ์ž…๋ ฅํ•œ N์˜ ์ž๋ฆฌ์ˆ˜๋ฅผ l์ด๋ผ ํ•œ๋‹ค๋ฉด l-1๊นŒ์ง€์˜ ์•ž์ž๋ฆฌ ๋ชจ๋“  ์ˆ˜๋ฅผ ๋”ํ•˜๊ณ , l์ž๋ฆฌ ์ˆ˜๋Š” ๋‚จ์€ ์ˆซ์ž๋งŒํผ๋งŒ ๊ณฑํ•ด์ค˜์„œ ์ตœ์ข…์ ์œผ๋กœ ๋”ํ•ด์ฃผ๋ฉด ๋.


โ˜… 30002 Joon Paberil โ˜…

N=int(input())

near=int(N**(1/2))**2
if near%2==0:
    start=(1,int(near**(1/2))+1)
else:
    start=(int(near**(1/2))+1,1)

diff=N-near
if diff <= near**(1/2):
    if near%2==0:
        print(start[0]+diff,start[1])
    else:
        print(start[0],start[1]+diff)
else:
    if near%2==0:
        print(1+int(near**(1/2)),start[1]-(diff-int(near**(1/2))))
    else:
        print(start[0]-(diff-int(near**(1/2))),1+int(near**(1/2)))

 

๐Ÿง˜๐Ÿผ‍โ™‚๏ธ ๊ทœ์น™์„ฑ์„ ํ™•์ธํ•˜๊ณ , ์ž…๋ ฅํ•œ N์ด๋ผ๋Š” ์ˆซ์ž๊ฐ€ ์กด์žฌํ•˜๋Š” ๊ฐ€์žฅ ํฐ ์ •์‚ฌ๊ฐํ˜•์˜ ํฌ๊ธฐ๋ฅผ ๋จผ์ € near๋กœ ํ™•์ธ. near๊ฐ€ ํ™€์ˆ˜ / ์ง์ˆ˜์— ๋”ฐ๋ผ ๊ฐ๊ฐ ์‹œ์ž‘ํ•˜๋Š” start ๋ฒˆํ˜ธ ํ™•์ธ. ๊ทธ๋ฆฌ๊ณ  ์ฐจ์ด diff๊ฐ€ near์˜ ์ „๋ฐ˜๋ถ€์ธ์ง€ ํ›„๋ฐ˜๋ถ€์ธ์ง€์— ๋”ฐ๋ผ ๋ถ„๊ธฐ ๋‚˜๋ˆ„์–ด์„œ ์ˆ˜ํ•™ ๊ทœ์น™์„ฑ ์ฐพ๊ณ  ์ฝ”๋“œ ์ž‘์„ฑ. ๊ทœ์น™๋งŒ ์ฐพ์œผ๋ฉด ๋œ๋‹ค.


โ˜… 30020 ์น˜์ฆˆ๋ฒ„๊ฑฐ ๋งŒ๋“ค๊ธฐ 2 โ˜…

import sys
input=sys.stdin.readline

A,B=map(int,input().split())

if A<=B:print('NO')
else:
    diff=A-B
    if diff>B:print('NO')
    else:
        print('YES')
        print(diff)
        for i in range(diff):
            if i != (diff-1):
                print('aba')
            else:
                b_cnt=(B-(diff-1))
                print('ab'*b_cnt+'a')

 

๐Ÿง˜๐Ÿผ‍โ™‚๏ธ ํ•œ ๊ฐœ์˜ ์น˜์ฆˆ๋ฒ„๊ฑฐ๋ฅผ ๋งŒ๋“ค ๋•Œ ํŒจํ‹ฐ์˜ ๊ฐœ์ˆ˜๋ฅผ a, ์น˜์ฆˆ์˜ ๊ฐœ์ˆ˜๋ฅผ b๋ผ ํ•˜๋ฉด ๋ฌด์กฐ๊ฑด a = b + 1์ด์–ด์•ผ ํ•œ๋‹ค. ๋”ฐ๋ผ์„œ A(a์˜ ํ•ฉ)์™€ B(b์˜ ํ•ฉ)์„ ๋ณด๋ฉด, A-B๊ฐ€ ๊ณง ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š” ์น˜์ฆˆ๋ฒ„๊ฑฐ์˜ ๊ฐœ์ˆ˜. ๋งŒ์•ฝ, B>=A์ด๊ฑฐ๋‚˜, A-B์ธ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š” ์น˜์ฆˆ๋ฒ„๊ฑฐ์˜ ๊ฐœ์ˆ˜๊ฐ€ ์น˜์ฆˆ์˜ ๊ฐœ์ˆ˜์ธ B๋ณด๋‹ค ํฌ๋‹ค๋ฉด, ์ด๋Š” ๊ณง A-B๊ฐœ์˜ ์น˜์ฆˆ๋ฒ„๊ฑฐ์— ๊ฐ๊ฐ ์น˜์ฆˆ 1๊ฐœ์”ฉ์„ ๋„ฃ์„ ์ˆ˜ ์—†๋‹ค๋Š” ๋œป์ด๋‹ค. ๋”ฐ๋ผ์„œ ํ•ด๋‹น ๊ฒฝ์šฐ๋ฅผ ์ œ์™ธํ•˜๊ณ  diff-1๊ฐœ์ˆ˜๋งŒํผ aba๋ฅผ ๋งŒ๋“ค๊ณ , ๋‚˜๋จธ์ง€ 1๊ฐœ๋Š” ๋‚จ์€ b count๋กœ b๋ฅผ ๊ตฌ์„ฑํ•˜๊ณ  a๋ฅผ ์•ž๋’ค์— ๋„ฃ์–ด์„œ ์น˜์ฆˆ๋ฒ„๊ฑฐ๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค. (๊ฐ€๋Šฅํ•œ ๊ฒฝ์šฐ ์•„๋ฌด๊ฑฐ๋‚˜ ์ถœ๋ ฅ ๊ฐ€๋Šฅํ•˜๋ฏ€๋กœ)


โ˜… 9471 ํ”ผ์‚ฌ๋…ธ ์ฃผ๊ธฐ โ˜…

import sys
input=sys.stdin.readline

for _ in range(int(input())):
    N,M=map(int,input().split()) #M>=2
    bef1,bef2 = 1,1
    for i in range(M**2):
        cur = (bef1+bef2)%M
        if bef2==cur==1:
            print(N,i+1)
            break
        else:
            bef1=bef2
            bef2=cur

 

๐Ÿง˜๐Ÿผ‍โ™‚๏ธ ํ”ผ๋ณด๋‚˜์น˜ ์ˆ˜์—ด์—์„œ mod m์„ ์ง„ํ–‰ํ–ˆ์„ ๋•Œ, ๋ชจ๋“  mod m์œผ๋กœ ์ง„ํ–‰ํ•œ ๋‚˜๋จธ์ง€๋Š” ๊ทœ์น™ ์ฃผ๊ธฐ์„ฑ์„ ๊ฐ–๋Š”๋‹ค(ํ”ผ์‚ฌ๋…ธ ์ฃผ๊ธฐ ์„ฑ์งˆ). ๋”ฐ๋ผ์„œ ๋งจ ์•ž์˜ mod m ๊ฒฐ๊ณผ 1 1์€ ์–ธ์  ๊ฐ€ ๋ฌด์กฐ๊ฑด ๋˜‘๊ฐ™์ด ์ง„ํ–‰๋˜๋ฉฐ, ๋ธŒ๋ฃจํŠธํฌ์Šค๋กœ 1 1์ด ๋˜ ๋‚˜์™”์„ ๋•Œ๊นŒ์ง€์˜ ์ฃผ๊ธฐ๋ฅผ ๊ตฌํ•ด์„œ ์ถœ๋ ฅํ•˜๋ฉด ๋œ๋‹ค. mod m์—์„œ ๋ฐ”๋กœ ์•ž๊ณผ ํ˜„์žฌ์˜ mod m ์ˆœ์„œ์Œ ๊ฐ€๋Šฅ ๊ฐœ์ˆ˜๋Š” ๋น„๋‘˜๊ธฐ ์ง‘์˜ ์›๋ฆฌ(0 ~ m-1 (mod m)์ด ์•ž๊ณผ ํ˜„์žฌ ๊ฐ€๋Šฅ ๊ฐœ์ˆ˜, ์ฆ‰ m*m์œผ๋กœ m^2)์— ์˜ํ•ด ์ตœ๋Œ€ m^2์ด๋ฏ€๋กœ m^2๊นŒ์ง€๋งŒ ๋Œ๋ฆฌ๋ฉด ๋œ๋‹ค.


โ˜… 2740 ํ–‰๋ ฌ ๊ณฑ์…ˆ โ˜…

 

import sys
input=sys.stdin.readline

N,M=map(int,input().split())
A=[]
for _ in range(N):
    A.append(list(map(int,input().split())))
B=[]
M,K=map(int,input().split())
for _ in range(M):
    B.append(list(map(int,input().split())))

ans=[]

for i in range(N):
    ans=[]
    for k in range(K):
        n=0
        for j in range(M):
            n+=(A[i][j]*B[j][k])
        ans.append(n)
    print(*ans)

 

๐Ÿง˜๐Ÿผ‍โ™‚๏ธ NxM ํ–‰๋ ฌ๊ณผ MxK ํ–‰๋ ฌ์˜ ๊ณฑ ๊ฒฐ๊ณผ๋Š” NxK ํ–‰๋ ฌ๋กœ ๋‚˜์˜จ๋‹ค. ๋”ฐ๋ผ์„œ for i in range(N)์œผ๋กœ ๋Œ๋ฆฌ๊ณ , for k in range(K)๋กœ ๋Œ๋ฆฐ ๋‹ค์Œ, ์ค‘๊ฐ„ ์ˆซ์ž for j in range(M)์„ ๋Œ๋ฆฌ๋ฉด ๋œ๋‹ค. ์•„๋ž˜ ํ–‰๋ ฌ ๊ณฑ ๊ทธ๋ฆผ ์ฐธ์กฐ

 

๐Ÿง˜๐Ÿผ‍โ™‚๏ธ

(1) i๊ฐ€ 0์ผ๋•Œ๋ถ€ํ„ฐ N-1์ผ ๋•Œ๊นŒ์ง€, ์ฒซ๋ฒˆ์งธ ํ–‰๋ ฌ์˜ ํ–‰์„ ์œ„์—์„œ๋ถ€ํ„ฐ ๋ˆ๋‹ค.

(2) ์ฒซ๋ฒˆ์งธ ํ–‰๋ ฌ์˜ ํŠน์ • iํ–‰์ผ ๋•Œ, ๋‘๋ฒˆ์งธ ํ–‰๋ ฌ์˜ ์ฒซ๋ฒˆ์งธ ์—ด๋ถ€ํ„ฐ ๋งˆ์ง€๋ง‰ ์—ด๊นŒ์ง€ ๋ˆ๋‹ค(k๊ฐ€ 0์ผ๋•Œ๋ถ€ํ„ฐ k-1์ผ๋•Œ๊นŒ์ง€)

(3) ์ฆ‰, ์ฒซ๋ฒˆ์งธ ํ–‰๋ ฌ์˜ ํŠน์ • iํ–‰(N)์ผ ๋•Œ & ๋‘๋ฒˆ์งธ ํ–‰๋ ฌ์˜ ํŠน์ • k์—ด(K)์ผ ๋•Œ: iํ–‰์˜ m๋ฒˆ์งธ ์›์†Œ์™€ k์—ด์˜ m๋ฒˆ์งธ ์›์†Œ๋ฅผ ์„œ๋กœ ๊ณฑํ•ด๋‚˜๊ฐ„ ํ•ฉ์„ ๊ฒฐ๊ณผ ํ–‰๋ ฌ์˜ ์›์†Œ๋กœ ๋ฐฐ์น˜

 

๐Ÿง˜๐Ÿผ‍โ™‚๏ธ ํ–‰๋ ฌ ๊ณฑ ์ฝ”๋“œ ์ž‘์„ฑ ์‹œ, NxM ํ–‰๋ ฌ๊ณผ MxKํ–‰๋ ฌ ๊ณฑ ํ˜•ํƒœ๋Š” ์ฒซ๋ฒˆ์งธ ํ–‰๋ ฌ์˜ ํ–‰๊ณผ ๋‘๋ฒˆ์งธ ํ–‰๋ ฌ์˜ ์—ด์„ ๋Œ๋ฉด์„œ(์ด์ค‘ ๋ฐ˜๋ณต๋ฌธ), M๊ฐœ์˜ ๊ณฑ ํ•ฉ์„ (์‚ผ์ค‘ ๋ฐ˜๋ณต๋ฌธ) ์ƒˆ๋กœ์šด ํ–‰๋ ฌ์˜ ์›์†Œ๋กœ ๋งŒ๋“ค๋ฉด ๋œ๋‹ค.


 

 

 

 

 

 

 

๋Œ“๊ธ€