답안 #1019664

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1019664 2024-07-11T06:42:52 Z Minbaev 홀-짝 수열 (IZhO11_oddeven) Python 3
0 / 100
15 ms 3048 KB
def binpow(a, b, mod=1e9 + 7):
    if b == 0:
        return 1
    if b % 2 == 0:
        c = binpow(a, b // 2, mod)
        return (c * c) % mod
    return (binpow(a, b - 1, mod) * a) % mod


def divi(a, b, mod=1e9 + 7):
    return (a * binpow(b, mod - 2, mod)) % mod


def solve():
    n = int(input())

    l = 1
    r = 1e9
    ans = -1
    while l <= r:
        mid = (l + r) // 2

        sum = mid * (mid + 1) // 2
        if sum >= n:
            ans = mid
            r = mid - 1
        else:
            l = mid + 1

    val = 0
    val = int(((ans * (ans + 1) // 2) - ans) * 2 + (ans - 1) + 1 - (ans * (ans + 1) // 2 - n) * 2)
    print(val)


if __name__ == "__main__":
    tt = 1
    # tt = int(input())
    while tt:
        solve()
        tt -= 1
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 2908 KB Output is correct
2 Correct 11 ms 3048 KB Output is correct
3 Correct 10 ms 2908 KB Output is correct
4 Correct 10 ms 2908 KB Output is correct
5 Correct 11 ms 2908 KB Output is correct
6 Correct 11 ms 2908 KB Output is correct
7 Correct 11 ms 2836 KB Output is correct
8 Correct 15 ms 2952 KB Output is correct
9 Correct 11 ms 2976 KB Output is correct
10 Correct 15 ms 3048 KB Output is correct
11 Incorrect 10 ms 2832 KB Output isn't correct
12 Halted 0 ms 0 KB -