No.826 Contact Network
タグ : / 解いたユーザー数 159
作問者 :
Problem Statement
Aoki lives in Y Town, a town of housing complexes.
$N$ people, including Aoki, live in Y Town, with one person living in each of house $1$, house $2$, ..., house $N$. Aoki lives in house $P$.
Y Town originally had a well-developed contact network: any houses $i,j\ (1\le i\lt j \le N)$ were directly connected by a telephone line and could contact each other in both directions.
However, the people in houses $i,j\ (1\le i\lt j \le N)$ such that $i$ and $j$ are coprime are, without exception, on bad terms, and they cut the telephone line directly connecting houses $i,j$. All other pairs of houses are still connected by telephone lines.
One day, Aoki got hold of a piece of secret information about Y Town. At that moment, no other resident knows this information.
All residents of Y Town, without exception, cannot keep a secret, so once they learn the information, they immediately spread the secret to other residents by telephone. They cannot tell people in houses not connected to theirs by a telephone line.
Find how many residents, including Aoki himself, can eventually learn the information.
The residents of Y Town never leave their homes and never contact anyone other than residents of Y Town, so the secret information is not spread by any means other than telephone exchanges between residents of Y Town.
Input
$N\ P$
The first line contains the number of residents of Y Town $N$ and Aoki's house number $P$, separated by a space.
Constraints
- $1 \le N \le 10^6$
- $1 \le P \le N$
- All inputs are integers.
Output
Output in one line the number of residents of Y Town who can learn the spread secret information.
Print a newline at the end.
Sample
Sample 1
Input
6 4
Output
4
The only remaining telephone lines are the edges shown as black lines below, and the houses to which information can be transmitted (directly or indirectly) from Aoki's house are the blue houses.
Sample 2
Input
17 13
Output
1
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。