์ƒˆ์†Œ์‹

๐Ÿงฎ PS

๋ฐฑ์ค€(boj) 1009 ํŒŒ์ด์ฌ - ๋ถ„์‚ฐ์ฒ˜๋ฆฌ

  • -

๋ฌธ์ œ ๋งํฌ : https://www.acmicpc.net/problem/1009

 

1009๋ฒˆ: ๋ถ„์‚ฐ์ฒ˜๋ฆฌ

์ž…๋ ฅ์˜ ์ฒซ ์ค„์—๋Š” ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ๊ฐœ์ˆ˜ T๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๊ทธ ๋‹ค์Œ ์ค„๋ถ€ํ„ฐ ๊ฐ๊ฐ์˜ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์— ๋Œ€ํ•ด ์ •์ˆ˜ a์™€ b๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ a < 100, 1 ≤ b < 1,000,000)

www.acmicpc.net

 

๋‹จ์ˆœํžˆ ๋ฌธ์ œํ•ด๊ฒฐ์„ ํ•˜๋ฉด ๊ฐ„๋‹จํ•˜์ง€๋งŒ, ์‹œ๊ฐ„์ดˆ๊ณผ๊ฐ€ ์ž๊พธ ๋ฐœ์ƒํ•˜์—ฌ ์—ฌ๋Ÿฌ๋ฒˆ ๊ณ ์ณ์•ผํ–ˆ๋‹ค.

1์˜ ์ž๋ฆฟ์ˆ˜๋งŒ ์ƒ๊ฐ์„ ํ•˜๋ฉด ๊ฐ„๋‹จํ•œ ๋ฌธ์ œ์˜€๋‹ค.

1, 5, 6์€ ๋ช‡์ œ๊ณฑ์„ ํ•ด๋„ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•˜๋ฉด ๋œ๋‹ค.

๋‚˜๋จธ์ง€ 2,3,7,8์€ ์ œ๊ณฑ์ด ๊ฑฐ๋“ญ๋จ์— ๋”ฐ๋ผ 4๊ฐ€์ง€ ๊ทœ์น™์— ์˜ํ•ด ์ˆ˜๊ฐ€ ๋‹ฌ๋ผ์ง„๋‹ค.

9์™€ 4๋Š” 2๊ฐ€์ง€ ๊ทœ์น™์ด ์žˆ์—ˆ๋‹ค.

(์ผ์˜์ž๋ฆฟ์ˆ˜๋งŒ ๋”ฐ์กŒ์„๋•Œ)

2์˜ ๊ฑฐ๋“ญ์ œ๊ณฑ : 2, 4 , 8 , 6 .... ๋ฐ˜๋ณต 

3์˜ ๊ฑฐ๋“ญ์ œ๊ณฑ : 3, 9,  7,  1 .... ๋ฐ˜๋ณต

๋‚˜๋จธ์ง€ ์ˆ˜๋“ค๋„ ๋งˆ์ฐฌ๊ฐ€์ง€ ํ˜•์‹

 

 

T = int(input())
for _ in range(T):
    a, b = map(str, input().split())
    b = int(b)
    if a[-1]=='1' or a[-1]=='5' or a[-1]=='6' : print(a[-1])   

    elif a[-1]=='2' or a[-1]=='3' or a[-1]=='7' or a[-1]=='8' :
        if b%4==0 : print((int(a[-1])**4)%10)
        elif b%4 == 1 : print(a[-1])
        elif b%4 == 2  : print((int(a[-1])**2)%10)
        elif b%4 == 3 : print((int(a[-1])**3)%10)

    elif a[-1]=='9' or a[-1]=='4':
        if b%2 == 0 : print((int(a[-1])**2)%10)
        elif b%2 == 1: print(a[-1])

    elif a[-1] == '0' : print(10)

 

Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.