Submission #333787

# Submission time Handle Problem Language Result Execution time Memory
333787 2020-12-07T19:24:39 Z limabeans Odd-even (IZhO11_oddeven) Python 3
0 / 100
31 ms 3948 KB
import sys
from math import *
from fractions import gcd
from random import * # randint(inclusive,inclusive)
readints=lambda:map(int, input().strip('\n').split())
from itertools import permutations, combinations
ALP = "abcdefghijklmnopqrstuvwxyz"
# print('', end=" ")
# for i in {1..5}; do echo "hi"; done

def randarr(n, lo, hi):
    assert(lo<=hi)
    return [randint(lo,hi) for _ in range(n)]


def randstr(n):
    s=''
    for _ in range(n):
        s += ALP[randint(0,25)]
    return s
    

def randtree(n):
    pass


##############################################################################


def asum(x):
    return x*(x+1)//2


def f(i):
    return asum(i)



n = int(input())
if n==1:
    print(1)
    sys.exit(0)

lo = 1
hi = n


while hi-lo>1:
    mid = (lo+hi)//2
    if f(mid) < n:
        lo = mid
    else:
        hi = mid


i = lo
n -= f(i)
n -= 1 # 0-index

cur = asum(i)+asum(i-1) + 1 + 2*n
print(cur)





# Verdict Execution time Memory Grader output
1 Runtime error 31 ms 3948 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -