Mock CCC '18 Contest 1 J5/S3 - A Simulation Problem

View as PDF

Submit solution


Points: 7 (partial)
Time limit: 0.16s
Java 0.6s
Python 0.6s
Memory limit: 1G

Problem type

Consider the following function:

function(N):
    # in some programming languages, 64-bit integers will be required to represent "threshold"
    threshold = N*(N-1)/2
    K = 1
    # in some programming languages, 64-bit integers will be required to represent "count"
    count = 0
    while K < N:
        L = K+1
        print K
        while L <= N:
            count += 1
            L += 1
            if 2 * count >= threshold:
                exit function
        K += 1

Given N, compute the last number this function prints out.

Constraints

2 \le N \le 10^9

Input Specification

The input consists of a single line containing the integer N.

Output Specification

Print, on a single line, the last number this function will print out.

Sample Input 1

4

Sample Output 1

1

Sample Input 2

7

Sample Output 2

2

Sample Input 3

10

Sample Output 3

3

Sample Input 4

1919

Sample Output 4

562

Sample Input 5

290976843

Sample Output 5

85225144

Comments


  • 0
    gavin_chen  commented on May 29, 2022, 2:58 p.m. edited

    Using the code the problem gave inputting 5 outputted 2 but using the editorial inputting 5 outputted 1? can someone tell me how the function the problem gave us works please? :) edit: nvm its not n-1 to 1 its n to 1