Jealous Numbers | 프로그래밍의 벗 PivotOJ
PivotOJ

Jealous Numbers

시간 제한: 3000ms메모리 제한: 256MB출처: NEERC Northern Subregional 2009BOJ 3559

문제

There is a trouble in Numberland, prime number pp is jealous of another prime number qq. She thinks that there are more integer numbers between aa and bb, inclusively, that are divisible by greater power of qq than that of pp. Help pp to get rid of her feelings. 

Let α(n,x)\alpha(n, x) be maximal kk such that nn is divisible by xkx^k. Let us say that a number nn is pp-dominating over~qq if α(n,p)>α(n,q)\alpha(n, p)>\alpha(n, q). Find out for how many numbers between aa and bb, inclusive are pp-dominating over~qq.

입력

The first line of the input file contains aa, bb, pp and qq (1ab10181 \le a \le b \le 10^{18}; 2p,q1092 \le p, q \le 10^9; pqp \ne q; pp and qq are prime).

출력

Output one number --- how many numbers nn between aa and bb, inclusive, are pp-dominating over qq.

힌트

In the given example 3, 9, 15 and 18 are 3-dominating over 2.

예제

예제 1

입력
1 20 3 2
출력
4
코드를 제출하려면 로그인하세요.