program kadai
implicit none
integer(8)  ::  a,b
integer(8) ::  c,d
integer(8)  ::  sa,sb,i,g
integer(8)  ::  aac,aad,bbc,bbd,alpha1,alpha2
integer(8)  ::  unta,untb,ans

read(*,*) a,b,c,d
a=a-1
aac=a/c
aad=a/d
bbc=b/c
bbd=b/d

sa=dble(c*d)
g=gcd(c,d)
alpha1=a/(sa/g)
alpha2=b/(sa/g)

untb=b-(bbc+bbd-alpha2)
unta=a-(aac+aad-alpha1)
ans=untb-unta

write(*,*) ans

stop
contains
integer function gcd(a,b)
    implicit none
    integer(8),intent(in)  ::  a,b
    integer(8)  ::  l,m,n
    m=a
    n=b
    do
        l=mod(m,n)
        if (l==0) then
            exit
        end if
        m=n
        n=l
    end do
    gcd=n
    return
end function gcd




end program kadai

; ModuleID = 'FIRModule'
source_filename = "FIRModule"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

@_QQcl.4bd32abc5b0fda64fa3d23b3f9c4183c = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_3953/source.f\00"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

; Function Attrs: noreturn
define void @_QQmain() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.4bd32abc5b0fda64fa3d23b3f9c4183c, i32 9)
  %6 = call i1 @_FortranAioInputInteger(ptr %5, ptr nonnull %1, i32 8)
  %7 = call i1 @_FortranAioInputInteger(ptr %5, ptr nonnull %2, i32 8)
  %8 = call i1 @_FortranAioInputInteger(ptr %5, ptr nonnull %3, i32 8)
  %9 = call i1 @_FortranAioInputInteger(ptr %5, ptr nonnull %4, i32 8)
  %10 = call i32 @_FortranAioEndIoStatement(ptr %5)
  %11 = load i64, ptr %1, align 8, !tbaa !3
  %12 = add i64 %11, -1
  store i64 %12, ptr %1, align 8, !tbaa !3
  %13 = load i64, ptr %3, align 8, !tbaa !3
  %14 = load i64, ptr %4, align 8, !tbaa !3
  %15 = load i64, ptr %2, align 8, !tbaa !3
  br label %16

16:                                               ; preds = %16, %0
  %.07.i = phi i64 [ %13, %0 ], [ %.0.i, %16 ]
  %.0.i = phi i64 [ %14, %0 ], [ %17, %16 ]
  %17 = srem i64 %.07.i, %.0.i
  %18 = icmp eq i64 %17, 0
  br i1 %18, label %_QFPgcd.exit, label %16

_QFPgcd.exit:                                     ; preds = %16
  %19 = mul i64 %14, %13
  %20 = sitofp i64 %19 to double
  %21 = fptosi double %20 to i64
  %22 = sdiv i64 %15, %14
  %23 = sdiv i64 %15, %13
  %24 = sdiv i64 %12, %14
  %25 = sdiv i64 %12, %13
  %sext = shl i64 %.0.i, 32
  %26 = ashr exact i64 %sext, 32
  %27 = sdiv i64 %21, %26
  %28 = sdiv i64 %12, %27
  %29 = sdiv i64 %15, %27
  %30 = add i64 %15, 1
  %31 = add i64 %11, %22
  %32 = add i64 %31, %23
  %.neg21 = sub i64 %30, %32
  %.neg18 = add i64 %.neg21, %24
  %.neg22 = add i64 %.neg18, %25
  %33 = sub i64 %.neg22, %28
  %34 = add i64 %33, %29
  %35 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.4bd32abc5b0fda64fa3d23b3f9c4183c, i32 25)
  %36 = call i1 @_FortranAioOutputInteger64(ptr %35, i64 %34)
  %37 = call i32 @_FortranAioEndIoStatement(ptr %35)
  %38 = call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable
}

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: read)
define i32 @_QFPgcd(ptr nocapture readonly %0, ptr nocapture readonly %1) local_unnamed_addr #1 {
  %3 = load i64, ptr %0, align 8, !tbaa !3
  %4 = load i64, ptr %1, align 8, !tbaa !3
  br label %5

5:                                                ; preds = %5, %2
  %.07 = phi i64 [ %3, %2 ], [ %.0, %5 ]
  %.0 = phi i64 [ %4, %2 ], [ %6, %5 ]
  %6 = srem i64 %.07, %.0
  %7 = icmp eq i64 %6, 0
  br i1 %7, label %8, label %5

8:                                                ; preds = %5
  %9 = trunc i64 %.0 to i32
  ret i32 %9
}

declare ptr @_FortranAioBeginExternalListInput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioInputInteger(ptr, ptr, i32) local_unnamed_addr

declare i32 @_FortranAioEndIoStatement(ptr) local_unnamed_addr

declare ptr @_FortranAioBeginExternalListOutput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

declare {} @_FortranAStopStatement(i32, i1, i1) local_unnamed_addr

attributes #0 = { noreturn }
attributes #1 = { nofree norecurse nosync nounwind memory(argmem: read) }

!llvm.module.flags = !{!0, !1, !2}

!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{!4, !4, i64 0}
!4 = !{!"any data access", !5, i64 0}
!5 = !{!"any access", !6, i64 0}
!6 = !{!"Flang Type TBAA Root"}
