#P5348. Mobius Lock Puzzle
Mobius Lock Puzzle
Mobius Lock Puzzle
One day, WD discovered a strange password lock. He remembered that before unlocking it, CX had given him some numbers. Unfortunately, WD forgot most of them, and he only recalls that after numbering the numbers from 1 to n, the following property holds: for every positive integer d (1 ≤ d ≤ n), the sum of all numbers at positions that are multiples of d is exactly equal to \(\mu(d)\), where \(\mu(d)\) is the Mobius function.
To unlock the lock, WD must determine the number at the m-th position. Since he is clueless about how to tackle the problem, he is asking for your help.
Recall: The Mobius function \(\mu(x)\) is defined as follows:
- \(\mu(1)=1\).
- \(\mu(x)=0\) if \(x\) has a squared prime factor.
- \(\mu(x)=(-1)^k\) if \(x\) is a product of \(k\) distinct primes.
It can be shown via Möbius inversion that the number at position m is given by:
[ a_m = \sum_{d\mid m} \mu(d),\mu\left(\frac{m}{d}\right). ]
inputFormat
The input consists of two integers n and m (1 ≤ m ≤ n), where n is the total number of numbers and m is the position whose value you need to determine.
outputFormat
Output a single integer representing the number at position m.
sample
6 1
1