#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, long);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, long *, long *, long *,
                          short *);
long gcd(long, short);
int main() {
  FILE *f = fopen("INP.TXT", "r");
  long l, r, a;
  short b;
  fscanf(f, "%ld %ld %ld %hd", &l, &r, &a, &b);
  fclose(f);
  a = a * b / gcd(a, b);
  l = (l % a) ? (l / a + 1) * a : l;
  f = fopen("OUT.TXT", "w");
  fprintf(f, "%ld\n", (r - l) / a + 1);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe89(%rip),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rcx
lea    -0x28(%rbp),%r8
lea    -0x2a(%rbp),%r9
call   1040 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rax
movswq -0x2a(%rbp),%rcx
imul   %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
movswl -0x2a(%rbp),%esi
call   1070 <gcd@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cqto
idiv   %rcx
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
cqto
idivq  -0x28(%rbp)
cmp    $0x0,%rdx
je     11fd <main+0xad>
mov    -0x18(%rbp),%rax
cqto
idivq  -0x28(%rbp)
add    $0x1,%rax
imul   -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    1205 <main+0xb5>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xe06(%rip),%rdi
lea    0xe07(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
sub    -0x18(%rbp),%rax
cqto
idivq  -0x28(%rbp)
mov    %rax,%rdx
add    $0x1,%rdx
lea    0xde0(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xea4(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe98(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0x18(%rsp),%rcx
lea    0x8(%rsp),%r8
lea    0x6(%rsp),%r9
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x8(%rsp),%rdi
movswl 0x6(%rsp),%eax
movslq %eax,%rsi
mov    %rdi,%rbx
imul   %rsi,%rbx
call   1070 <gcd@plt>
mov    %rax,%rcx
or     %rbx,%rax
shr    $0x20,%rax
je     11c8 <main+0x78>
mov    %rbx,%rax
cqto
idiv   %rcx
mov    %rax,%rcx
jmp    11d0 <main+0x80>
mov    %ebx,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%ecx
mov    %rcx,0x8(%rsp)
mov    0x10(%rsp),%rsi
mov    %rsi,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     11f0 <main+0xa0>
mov    %rsi,%rax
cqto
idiv   %rcx
jmp    11f6 <main+0xa6>
mov    %esi,%eax
xor    %edx,%edx
div    %ecx
add    $0x1,%rax
imul   %rcx,%rax
test   %rdx,%rdx
cmove  %rsi,%rax
mov    %rax,0x10(%rsp)
lea    0xe09(%rip),%rdi
lea    0xe0a(%rip),%rsi
call   1060 <fopen@plt>
mov    0x18(%rsp),%rcx
sub    0x10(%rsp),%rcx
mov    %rax,%rbx
mov    0x8(%rsp),%rsi
mov    %rcx,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     1245 <main+0xf5>
mov    %rcx,%rax
cqto
idiv   %rsi
jmp    124b <main+0xfb>
mov    %ecx,%eax
xor    %edx,%edx
div    %esi
add    $0x1,%rax
lea    0xdce(%rip),%rsi
mov    %rbx,%rdi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"INP.TXT\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [16 x i8] c"%ld %ld %ld %hd\00"
@.str.3 = [8 x i8] c"OUT.TXT\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [5 x i8] c"%ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i16
store i32 0, i32* %1
%7 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %2
%8 = load i32*, i32** %2
%9 = call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i64* %3, i64* %4, i64* %5, i16* %6)
%10 = load i32*, i32** %2
%11 = call i32 @fclose(i32* %10)
%12 = load i64, i64* %5
%13 = load i16, i16* %6
%14 = sext i16 %13 to i64
%15 = mul nsw i64 %12, %14
%16 = load i64, i64* %5
%17 = load i16, i16* %6
%18 = call i64 @gcd(i64 %16, i16 signext %17)
%19 = sdiv i64 %15, %18
store i64 %19, i64* %5
%20 = load i64, i64* %3
%21 = load i64, i64* %5
%22 = srem i64 %20, %21
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %0
%25 = load i64, i64* %3
%26 = load i64, i64* %5
%27 = sdiv i64 %25, %26
%28 = add nsw i64 %27, 1
%29 = load i64, i64* %5
%30 = mul nsw i64 %28, %29
br label %33
31: ; preds = %0
%32 = load i64, i64* %3
br label %33
33: ; preds = %31, %24
%34 = phi i64 [ %30, %24 ], [ %32, %31 ]
store i64 %34, i64* %3
%35 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %35, i32** %2
%36 = load i32*, i32** %2
%37 = load i64, i64* %4
%38 = load i64, i64* %3
%39 = sub nsw i64 %37, %38
%40 = load i64, i64* %5
%41 = sdiv i64 %39, %40
%42 = add nsw i64 %41, 1
%43 = call i32 @fprintf(i32* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i64 %42)
%44 = load i32*, i32** %2
%45 = call i32 @fclose(i32* %44)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"INP.TXT\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [16 x i8] c"%ld %ld %ld %hd\00"
@.str.3 = [8 x i8] c"OUT.TXT\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [5 x i8] c"%ld\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = alloca i16
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = bitcast i64* %1 to i8*
%7 = bitcast i64* %2 to i8*
%8 = bitcast i64* %3 to i8*
%9 = bitcast i16* %4 to i8*
%10 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i64* %1, i64* %2, i64* %3, i16* %4)
%11 = call i32 @fclose(i32* %5)
%12 = load i64, i64* %3
%13 = load i16, i16* %4
%14 = sext i16 %13 to i64
%15 = mul nsw i64 %12, %14
%16 = call i64 @gcd(i64 %12, i16 signext %13)
%17 = sdiv i64 %15, %16
store i64 %17, i64* %3
%18 = load i64, i64* %1
%19 = srem i64 %18, %17
%20 = sdiv i64 %18, %17
%21 = icmp eq i64 %19, 0
%22 = add nsw i64 %20, 1
%23 = mul nsw i64 %22, %17
%24 = select i1 %21, i64 %18, i64 %23
store i64 %24, i64* %1
%25 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%26 = load i64, i64* %2
%27 = load i64, i64* %1
%28 = sub nsw i64 %26, %27
%29 = load i64, i64* %3
%30 = sdiv i64 %28, %29
%31 = add nsw i64 %30, 1
%32 = call i32 @fprintf(i32* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i64 %31)
%33 = call i32 @fclose(i32* %25)
ret i32 0
}