#P8753. [蓝桥杯 2021 省 AB2] 小平方

[蓝桥杯 2021 省 AB2] 小平方

Problem Description

Xiaolan found that, for a positive integer nn and a positive integer vv less than nn, after squaring vv and taking it modulo nn, the result may be less than half of nn, or it may be greater than or equal to half of nn.

Ask: among the integers from 11 to n1n-1, how many numbers have a remainder less than half of nn when their squares are divided by nn.

For example, when n=4n=4, the remainders of 12,22,321^2, 2^2, 3^2 divided by 44 are all less than half of 44.

Another example: when n=5n=5, the remainders of 121^2 and 424^2 divided by 55 are both 11, which is less than half of 55. But the remainders of 222^2 and 323^2 divided by 55 are both 44, which is greater than or equal to half of 55.

Input Format

The input contains one line with an integer nn.

Output Format

Output one integer, the number of integers that satisfy the condition.

5

2

Hint

For all test cases, 1n100001 \leq n \leq 10000.

Lanqiao Cup 2021 Round 2 Provincial Contest, Group A Problem F (Group B Problem G).

Translated by ChatGPT 5