program anti_division
    implicit none
    integer(8):: a,b,c,d,gcd,ans_a, ans_b

    read*, a,b,c,d

    gcd = c*d/lcm(c,d)

    ans_a = (a-1) - (a-1)/c - (a-1)/d +(a-1)/gcd
    ans_b = b - b/c - b/d + b/gcd

    print*, ans_b - ans_a

contains
recursive function lcm(a,b) result(ret)
    integer(8),intent(in):: a,b
    integer(8):: ret

    if (mod(a,b) == 0) then
        ret = b
        return
    end if
    ret = lcm(b,mod(a,b))
end function
end program anti_division
; 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.bd140b6de17bd52bdfd3350c2592a268 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_3948/source.f\00"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

define void @_QQmain() local_unnamed_addr {
  %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.bd140b6de17bd52bdfd3350c2592a268, i32 5)
  %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 %3, align 8, !tbaa !3
  %12 = load i64, ptr %4, align 8, !tbaa !3
  %13 = mul i64 %12, %11
  %14 = call i64 @_QFPlcm(ptr nonnull %3, ptr nonnull %4)
  %15 = sdiv i64 %13, %14
  %16 = load i64, ptr %1, align 8, !tbaa !3
  %17 = add i64 %16, -1
  %18 = sdiv i64 %17, %11
  %19 = sdiv i64 %17, %12
  %20 = sdiv i64 %17, %15
  %21 = load i64, ptr %2, align 8, !tbaa !3
  %22 = sdiv i64 %21, %11
  %23 = sdiv i64 %21, %12
  %24 = sdiv i64 %21, %15
  %25 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.bd140b6de17bd52bdfd3350c2592a268, i32 12)
  %.neg7 = sub i64 1, %16
  %.neg12 = add i64 %.neg7, %18
  %.neg5.neg = add i64 %.neg12, %19
  %26 = add i64 %.neg5.neg, %21
  %27 = add i64 %20, %22
  %28 = add i64 %27, %23
  %29 = sub i64 %26, %28
  %30 = add i64 %29, %24
  %31 = call i1 @_FortranAioOutputInteger64(ptr %25, i64 %30)
  %32 = call i32 @_FortranAioEndIoStatement(ptr %25)
  ret void
}

; Function Attrs: nofree nosync nounwind memory(argmem: read)
define i64 @_QFPlcm(ptr nocapture readonly %0, ptr nocapture readonly %1) local_unnamed_addr #0 {
  %3 = alloca i64, align 8
  %4 = load i64, ptr %0, align 8, !tbaa !3
  %5 = load i64, ptr %1, align 8, !tbaa !3
  %6 = srem i64 %4, %5
  %7 = icmp eq i64 %6, 0
  br i1 %7, label %10, label %8

8:                                                ; preds = %2
  store i64 %6, ptr %3, align 8, !tbaa !3
  %9 = call i64 @_QFPlcm(ptr nonnull %1, ptr nonnull %3)
  br label %10

10:                                               ; preds = %2, %8
  %.0 = phi i64 [ %9, %8 ], [ %5, %2 ]
  ret i64 %.0
}

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

attributes #0 = { nofree 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"}
