You are a scholar who studies mathematical formulas. The formula is calculated by the following steps:
Positive integers N and M are given.
For all integers k between 1 and N, calculate the following values:
Assistant
Let's break down the problem step by step.
We are given two positive integers N and .
⌊kN⌋×⌊⌊kN⌋+1M⌋
Find the product of the N calculated values.
You are researching the conditions under which the value of a mathematical formula is 0.
Of the integers k between 1 and N, find the number of those that satisfy the following conditions:
The value calculated in step 2 using k is 0.
Constraints
1≤N,M≤1012
All inputs are integers.
Input
Input is given from standard input in the following format.
code
N M
Output
Output the number of integers k between 1 and N that satisfy the condition.
M
For each integer k between 1 and N, we need to calculate the following value:
vk=⌊kN⌋×⌊⌊kN⌋+1M⌋
We want to find the number of integers k between 1 and N such that vk=0.
Let's analyze the condition vk=0:
vk=0 if and only if either ⌊kN⌋=0 or ⌊⌊kN⌋+1.
⌊kN⌋=0 if and only if k≥N.
⌊⌊kN⌋+1 if and only if or .
So, the condition vk=0 is satisfied if and only if:
k≥N or
M=0 or ⌊kN⌋+1>M
Now, let's count the number of integers k that satisfy this condition:
If M=0, then all k≥N satisfy the condition, so there are N such integers.
If M>0, we need to count the integers k such that ⌊kN⌋+1>M. This is equivalent to finding the number of integers k such that ⌊kN⌋≤M−1. We can solve this using a loop or a binary search.
Here's the Python code to solve the problem:
python
import math
def count_zero_values(N: int, M: int) -> int:
if M == 0:
return N
else:
return sum(1 for k in range(1, N+1) if math.floor(N/k) <= M-1)
# Read input from standard input
N, M = map(int, input().split())
# Call the function and print the result
print(count_zero_values(N, M))