問題一覧 > 通常問題

No.826 Contact Network

レベル : / AI推定難易度 : 1200 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 159
作問者 : Pachicobue / テスター : kopricky
お気に入りにしたユーザー ProblemId : 2982 / 自分の提出
問題文最終更新日: 2019-05-04 00:28:10
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 213 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。