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:

Copy
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

2N109

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

Copy
4

Sample Output 1

Copy
1

Sample Input 2

Copy
7

Sample Output 2

Copy
2

Sample Input 3

Copy
10

Sample Output 3

Copy
3

Sample Input 4

Copy
1919

Sample Output 4

Copy
562

Sample Input 5

Copy
290976843

Sample Output 5

Copy
85225144

Comments


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

    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 N1 to 1 its N to 1