#P15210. [NWERC 2025] Dreamcatcher

[NWERC 2025] Dreamcatcher

Description

Lately, you are plagued by horrifying nightmares. In those dreams, a swarm of angry Fenwick bees chases you around a tree with heavy and light branches. You hate getting stung by their fiddling bits. Therefore, you decided to build a dreamcatcher three days ago, but the process is tricky, and you can't figure out the details.

Planning your dreamcatcher became so stressful that you spent the last three nights awake, thinking about long strings of yarn, Carmichael numbers, and geometry. The only progress so far is some incomprehensible drawings (see Figure D.11) and the observation that the length of a chord that spans θ\theta degrees of a circle with radius rr is 2rsin(θ/2)2r \cdot \sin(\theta/2). But how is this going to help? You would rather have the dreams about Fenwick bees again than being tormented by this dreadful project for one more day. You need to solve this now!

Figure D.11: A dreamcatcher with 88 notches, showing two ways of wrapping it in a string of yarn. The dreamcatcher on the left spans 22 notches per chord, while the dreamcatcher on the right spans 33 notches per chord.

To build a dreamcatcher, you take a wheel with nn evenly spaced notches, numbered from 11 to nn. You wrap a string of yarn around this wheel, spanning kk notches per chord: starting at notch 11, you repeatedly connect the yarn kk notches ahead until you reach notch 11 again. For example, with n=8n = 8 and k=3k = 3, you would go from notch 11 to 44, then 77, 22, 55, 88, 33, 66, 11.

A dreamcatcher's effectiveness depends on the amount of used yarn. You need to choose kk, the number of notches to span per chord, such that the total length of yarn is maximized. The answer does not depend on the radius of the dreamcatcher.

Input Format

The input consists of:

  • One line with an integer nn (3n1093 \leq n \leq 10^9), the number of notches on the wheel.

Output Format

Output an integer kk (1k<n1 \leq k < n) that maximizes the length of used yarn when spanning kk notches per chord. If there are multiple valid solutions, you may output any one of them.

8
3
5
2
6
5