Problem:


Score : 300 points

Problem Statement

You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Constraints

1\leq A\leq B\leq 10^{18}

1\leq C,D\leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

Print the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Sample Input 1

4 9 2 3

Sample Output 1

2

5 and 7 satisfy the condition.

Sample Input 2

10 40 6 8

Sample Output 2

23

Sample Input 3

314159265358979323 846264338327950288 419716939 937510582

Sample Output 3

532105071133627368



Sample input:
4 9 2 3


Sample output:
2

Submission status: Wrong Answer

Solution code:
import fractions

a,b,c,d = map(int,input().split())
#print(a,b,c,d)
gcd = int(fractions.gcd(c,d))
lcm = int(c*d / gcd)
#print(gcd,lcm)


c_div1 = int((a-1) / c)
c_div2 = int(b / c)
d_div1 = int((a-1) / d) 
d_div2 = int(b / d)
lcm_div1 = int((a-1) / lcm)
lcm_div2 = int(b / lcm)

ans = int(c_div2 - c_div1) + int(d_div2 - d_div1) - int(lcm_div2 - lcm_div1)
#print(c_div1,c_div2,d_div1,d_div2,lcm_div1,lcm_div2)
print(int(b - a - ans + 1))

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
rem = b - a + 1
pattern1 = (rem + (c - 1 - a % c)) // c
pattern2 = (rem + (d - 1 - a % d)) // d
bi = c * d
pattern3 = (rem + (bi - 1 - a % bi)) // bi
print(rem - pattern1 - pattern2 + pattern3)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
ans = set()
for i in range(A//C + 1, B //C + 1):
    ans.add(i*C)

for i in range(A//D + 1, B //D + 1):
    ans.add(i*D)
    


print(B - A + 1 - len(ans))

Submission status: Wrong Answer

Solution code:
import fractions

def calc_lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

A, B, C, D = map(int, input().split())
lcm = calc_lcm(C, D)

ac = (A-1) // C
bc = B // C
ad = (A-1) // D
bd = B // D
alcm = (A-1) // lcm
blcm = (B-1) // lcm

num_c = bc - ac
num_d = bd - ad
num_lcm = blcm - alcm

ans = (B - A + 1) - (num_c + num_d - num_lcm)

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

A,B,C,D= map(int,input().split())


#A-BまでのCの個数

Cnum=int((B-A)//C)+ ((B-A)%C >= (C-A%C))
Dnum=int((B-A)//D)+ ((B-A)%D >= (D-A%D))

CD= int(C*D/(fractions.gcd(C,D)))

CDnum=int((B-A)//CD)+ ((B-A)%CD >= (CD-(A%CD)))

print(B-A-Cnum-Dnum+CDnum)

Submission status: Wrong Answer

Solution code:

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y) #再帰定義

def lcm(x, y):
    return (x * y) // gcd(x, y)


A,B,C,D = map(int,input().split())

diffs = B - A

if diffs < min(C,D):
    print(diffs + 1)
    exit()

C_num = diffs // C
D_num = diffs // D

sc = lcm(C,D)


sc_num = diffs // sc


print(diffs - (C_num + D_num - sc_num))

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd

def number_calc(A,B,x):
    left = math.ceil(A/x)
    right = math.floor(B/x)
    res = max(right-left+1,0)
    return res

A,B,C,D = map(int,input().split())

ans = B-A+1
ans -=number_calc(A,B,C)
ans -=number_calc(A,B,D)
ans +=number_calc(A,B,(C*D)/gcd(C,D))

print(ans)

Submission status: Wrong Answer

Solution code:
import math
import sys

fin = sys.stdin.readline
A, B, C, D = [int(elem) for elem in fin().split()]


# A以上B以下のCの倍数の個数
def warikiru(A, B, C):
    return int(B / C) - math.ceil(A / C) + 1


# 最大公約数
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


# 最小公倍数
def lcm(a, b):
    return a * b // gcd(a, b)


warikiru_num = warikiru(A, B, C) + warikiru(A, B, D) - warikiru(A, B, lcm(C, D))

print(int(B - A + 1 - warikiru_num))

Submission status: Wrong Answer

Solution code:
import math
import sys
input=sys.stdin.readline
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())
 
def ss_raw():
    return input().split()
 
def ints_raw():
    return tuple(map(int, ss_raw()))


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


DIV = 10**9+7

def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret
    
def mod_modify(a,mod):
    return (a+mod)%mod

def cal_ABC(A,B,C):
    AC = math.ceil(A/C)
    BC = (B//C)
    return max(BC-AC+1,0)


def gcd(a, b):
    if(b == 0):
        return a
    return gcd(b, a % b)

def main():
    ans =0
    A,B,C,D = ints_raw()
    total = B-A+1
    dC = cal_ABC(A,B,C)
    dD = cal_ABC(A,B,D)
    dCD = cal_ABC(A,B,C*D//gcd(max(C,D),min(C,D)))
    return total-dC-dD+dCD

print(main())

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())

lower_C = -(-A//C)
upper_C = B//C
num_C = upper_C - lower_C + 1
lower_D = -(-A//D)
upper_D = B//D
num_D = upper_D - lower_D + 1
lower_CD = -(-A//(C*D))
upper_CD = B//(C*D)
num_CD = upper_CD - lower_CD + 1

print(B - A + 1 - num_C - num_D + num_CD)

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
n = a[1]-a[0]+1
wac = int(a[1]/a[2])-int(a[0]/a[2])
if a[0]%a[2]==0:
    wac+=1
wad= int(a[1]/a[3])-int(a[0]/a[3])
if a[0]%a[3]==0:
    wad+=1
cd = int(a[1]/(a[3]*a[2]))-int(a[0]/(a[3]*a[2]))
if a[0]%(a[3]*a[2])==0:
    cd +=1
print(n-wac-wad+cd)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())

ans = 0
for num in range(A, B):
    if num % C != 0:
        if num % D != 0:
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import math, fractions
A,B,C,D = map(int, input().split(' '))

def countNum(nSmall, nLarge, nD):
    # find smaller than nLarge
    largest = (nLarge // nD) * nD
    smallest = math.ceil(nSmall / nD) * nD

    if largest == 0:
        return 0
    if smallest > largest:
        return 0
    return (largest-smallest) // nD + 1

numC = countNum(A,B,C)
numD = countNum(A,B,D)
numCD = countNum(A,B,(C*D)//fractions.gcd(C,D) )

able = numC + numD - numCD

print(B - A + 1 - able)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())

e=b-a
print(e - int(e/c) - int(e/d) )

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
  
def lcm(a, b):
	return a * b // gcd (a, b)
  
A,B,C,D=map(int, input().split())
divC = B//C - A//C
divD = B//D - A//D
CD = lcm(C,D)
divCD = B//CD - A//CD
divsum=divC+divD-divCD
answer=B-A+1-divsum

print(answer)

Submission status: Wrong Answer

Solution code:
import fractions
A, B, C, D = (int(x) for x in input().split())

C_ = int(B/C) - int(A/C)
if A % C == 0:                                                                                                                                                                                              
    C_ += 1                                                                                                                                                                                                 
D_ = int(B/D) - int(A/D)
if A % D == 0:                                                                                                                                                                                              
    D_ += 1                                                                                                                                                                                                 

E = C * D / fractions.gcd(C, D)
E_ = int(B/E) - int(A/E)
if A % E == 0:                                                                                                                                                                                              
    E_ += 1                                                                                                                                                                                                 

ans = B - A + 1 - C_ - D_ + E_
print(ans)

Submission status: Wrong Answer

Solution code:
import math

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

def lcm(a,b):
  if a >= b:
    return a*b//gcd(a,b)
  else:
    return a*b//gcd(b,a)


A, B, C, D = map(int, input().split())

k1 = math.ceil(A / C)
k2 = B // C
k3 = math.ceil(A / D)
k4 = B // D

if k1 == 0:
  k5 = k2 - k1
else:
  k5 = k2 - k1 + 1
if k3 == 0:
  k6 = k4 - k3
else:
  k6 = k4 - k3 + 1

lcm_num = lcm(C, D)
k7 = math.ceil(A / lcm_num)
k8 = B // lcm_num

if k7 == 0:
  k9 = k8 - k7
else:
  k9 = k8 - k7 + 1

print(B - A + 1 - k5 - k6 + k9)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

a,b,c,d = [int(i) for i in input().split()]

def count_num(num):
  a_1 = num//c
  a_2 = num//d
  a_3 = num//(c * d / gcd(c, d))
  return num - (a_1 + a_2 - a_3)

print(int(count_num(b) - count_num(a-1)))

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int, input().split())

import math

def calc(x):
  left = math.ceil(A/x)*x
  right = math.floor(B/x)*x
  print(x, left, right)
  if A<=left<=right<=B:
    return (right - left) // x + 1
  else:
    return 0

from fractions import gcd

lcm = lambda a, b: a*b//gcd(a,b)

print((B-A)+1 - calc(C) - calc(D) + calc(lcm(C,D)))

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())

x = c
y = d
while y:
    x, y = y, x % y
gcd = x
lcm = c * d // gcd

sc = (b // c - (a-1) // c)
sd = (b // d - (a-1) // d)
slcm = b // lcm - a // lcm
print(b-a+1 - sc - sd + slcm)

# 1 2 3 4 5 6 7 8 9
#   x   x   x   x
#     x     x     x

Submission status: Wrong Answer

Solution code:
import sys

def gcd(a, b):
    """Euclidean Algorithm"""
    while b != 0:
        a, b = b, a % b
    return a


def lcm(a, b):
    return (a * b) // gcd(a, b)


def main():
    input = sys.stdin.readline
    A, B, C, D = map(int, input().split())
    E = lcm(C, D)

    total = B - A + 1
    multi_c = (B - C + 1) // C - (A - C + 1) // C
    multi_d = (B - D + 1) // D - (A - D + 1) // D
    multi_e = (B - E + 1) // E - (A - E + 1) // E
    return total - (multi_c + multi_d - multi_e)


if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


A,B,C,D = map(int,input().split())

l = [i  for i in range(A, B+1)]

c_cnt = 0
i=1
while(True):
    if(C*i >=A and C*i <= B):
        c_cnt +=1
    elif(C*i > B):
        break
    i += 1

d_cnt = 0
i=1
while(True):
    if(D*i >= A and D*i <=B):
        d_cnt += 1
    elif(D*i > B):
        break
    i +=1

cd_lcm = lcm(C,D)

cd_cnt = 0
i=1
while(True):
    if(cd_lcm*i >= A and cd_lcm*i <=B):
        cd_cnt += 1
    elif(cd_lcm*i > B):
        break
    i +=1

print('l:{0},c:{1},d{2},cd:{3}'.format(len(l),c_cnt,d_cnt,cd_cnt))
print(len(l) - c_cnt - d_cnt + cd_cnt)

Submission status: Wrong Answer

Solution code:
num = input().split(" ")
a = int(num[0])
b = int(num[1])
c = int(num[2])
d = int(num[3])
print(b - b//c -b//d +b//(c*d) -(a -a//c -a//d + a//(c*d)))

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int,input().split())

s = C * D
Am = A - 1

min1 = Am // C
min2 = Am // D
min3 = Am // s

max1 = B // C
max2 = B // D
max3 = B // s

n = B - max1 - max2 + max3 - (Am - min1 - min2 + min3)
print(n)

Submission status: Wrong Answer

Solution code:
from math import ceil,floor
A,B,C,D = map(int,input().split())

def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)

def lcm(a,b):
    return a*b//gcd(a,b)

def keisan(s,e,d):
    if floor(s/d) != ceil(e/d):
        if s%d == 0:
            return floor(e/d) - floor(s/d) + 1
        else:
            return floor(e/d) - floor(s/d)
    elif e-s < d:
        return 0
    else:
        return 1

print(B-A+1-(keisan(A,B,C)+keisan(A,B,D)-keisan(A,B,lcm(C,D))))

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int, input().split())
sub=b-a
tmpc=sub//c
tmpd=sub//d
import fractions
def lcm(x,y):
    return (x*y) // fractions.gcd(x,y)
tmplcm=sub//lcm(c,d)
print(sub-(tmpc+tmpd-tmplcm))

Submission status: Wrong Answer

Solution code:
# C問題
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

A, B, C, D = map(int, input().split())
E = lcm(C, D)
ac = A // C
bc = B // C
ad = A // D
bd = B // D
ae = A // E
be = B // E
if A % C == 0:
    ac -= 1
if A % D == 0:
    ad -= 1
xx = bc - ac + bd - ad
yy = be - ae
print(B - A + 1 - xx + yy)

Submission status: Wrong Answer

Solution code:
import math

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(a,b):
  return a*b//gcd(a,b)

A, B, C, D = [int(i) for i in input().split()]

C_count = math.floor(B/C) - math.ceil(A/C) + 1
D_count = math.floor(B/D) - math.ceil(A/D) + 1
both_count = math.floor(B/lcm(C, D)) - math.ceil(A/lcm(C, D)) + 1
# print(C_count)
# print(D_count)
# print(both_count)
answer = B - A + 1 - (C_count + D_count - both_count)
print(answer)

Submission status: Wrong Answer

Solution code:
def main():
     def gcd(a, b):
          while b:
               a, b = b, a % b
          return a

     def lcm(a, b):
          return a * b // gcd (a, b)
     a,b,c,d=map(int,input().split())
     ans=b-a+1
     ans-=(b+1)//c-(a+1)//c
     ans-=(b+1)//d-(a+1)//d
     cd=lcm(c,d)
     ans+=(b+1)//(cd)-(a+1)//(cd)
     print(ans)
     
if __name__=='__main__':
     main()

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
  
def lcm(a, b):
	return a * b // gcd (a, b)
  
A,B,C,D=map(int, input().split())
print(A,B,C,D)
divC = B//C - A//C
divD = B//D - A//D
CD = lcm(C,D)
divCD = B//CD - A//CD
divsum=divC+divD-divCD
answer=B-A+1-divsum

print(answer)

Submission status: Wrong Answer

Solution code:

a, b, c, d = map(int, input().split())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
def lcm(x, y):
    return (x * y) // gcd(x, y)

div1 = b//c - a//c

div2 = b//d - a//d

e = lcm(c,d)
div3 = b//e - a//e
ans = b-a+1 - div1 - div2 + div3
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

a, b, c, d = map(int, input().split())

# l = lcm(c,d)
g = fractions.gcd(c, d)
l = int((c * d) / g)

def num(x, y, z): #x以上y以下でzで割り切れる数の個数
    ent = int((x + z - 1) / z)
    att = int(y / z)
    if ent >= att:
        return 0
    else:
        return att - ent + 1

gyaku = num(a, b, c) + num(a, b, d) - num(a, b, l)
print(b - a + 1 - gyaku)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())

lower_C = -(-A//C)
upper_C = B//C
num_C = upper_C - lower_C + 1
lower_D = -(-A//D)
upper_D = B//D
num_D = upper_D - lower_D + 1
lower_CD = -(-A/(C*D))
upper_CD = B//(C*D)
num_CD = upper_CD - lower_CD + 1

print(B - A + 1 - num_C - num_D + num_CD)

Submission status: Wrong Answer

Solution code:
import fractions
import numpy as np
import os
import sys

A,B,C,D=map(int,input().split())

E=C*D/fractions.gcd(C,D)

A0=int(A/C)
B0=int(B/C)
if(A%C==0):
    B0+=1
C0=B0-A0



A1=int(A/D)
B1=int(B/D)
if(A%D==0):
    B1+=1
D1=B1-A1

A2=int(A/E)
B2=int(B/E)
if(A%E==0):
    B2+=1
E2=B2-A2

print((B-A+1)-(C0+D1-E2))

Submission status: Wrong Answer

Solution code:
import math
import fractions
a,b,c,d = map(int,input().split())
cc = math.floor(b/c) - math.floor((a-1)/c)
dd = math.floor(b/d) - math.floor((a-1)/d)
lcm = int(c*d / fractions.gcd(c,d))
gcd = math.floor(b/lcm) - math.floor((a-1)/lcm)
print(b-a+1-(cc+dd-gcd))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

a,b,c,d = [int(i) for i in input().split()]

def count_num(num):
  a_1 = num//c
  a_2 = num//d
  a_3 = num//(c * d / gcd(c, d))
  return num - (a_1 + a_2 - a_3)

print(int(count_num(b) - count_num(a)))

Submission status: Wrong Answer

Solution code:
import time
start_time = time.time()
numbers = input().split(' ')

a = int(numbers[0])	
b = int(numbers[1])
c = int(numbers[2])
d = int(numbers[3])

count = 0
for i in range(a, b+1):
	end_time = time.time()
	if end_time - start_time > 1.9:
		print(0)
		break
	if 	i % c != 0 and i % d != 0:
		count += 1
print(count)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
ba = B - A
cd = ba // C + ba // D
if cd % 2 == 0:
    ans = 1
else:
    ans = 0
print(ba-cd+ans)

Submission status: Wrong Answer

Solution code:
inputs = [int(s) for s in input().split()]
a = inputs[0]
b = inputs[1]
c = inputs[2]
d = inputs[3]
count = 0
minCD = min(c, d)
maxCD = max(c, d)

x0 = b-a+1
x1 = b//minCD - (a-1)//minCD
x2 = b//maxCD - (a-1)//maxCD
x3 = b//(minCD*maxCD) - (a-1)//(minCD*maxCD)

if maxCD % minCD == 0:
    print(x0-x1)
else:
    print(x0-(x1+x2-x3))

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())

print(A)

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())

import fractions

x = b//c - a//c
y = b//d - a//d
e = c*d//fractions.gcd(c,d)
z = b//e - a//e

print(b-a+1-x-y+z)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

from fractions import gcd
from math import ceil,floor

A,B,C,D=map(int, input().split())

ans = 0

Cans = floor(B/C) - ceil(A/C) + 1
Dans = floor(B/D) - ceil(A/D) + 1

CD = C * D / gcd(C,D)
CDans = floor(B/CD) - ceil(A/CD) + 1

ans = (B-A+1) - (Cans + Dans - CDans)

print(ans)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a


ans_C = int(B/C) - int((A-1)/C)
ans_D = int(B/D) - int((A-1)/D)
CD = C*D // gcd(C, D)
ans_CD = int(B/CD) - int((A-1)/CD)

print(B-A+1 -(ans_C + ans_D - ans_CD))

Submission status: Wrong Answer

Solution code:
from math import *
from fractions import *
a,b,c,d=map(int,input().split())
lcm=lambda x,y: x*y//gcd(x,y)

print(b-a+1 - ((b-a+1)//c + (b-a+1)//d - (b-a+1)//lcm(c,d)))

Submission status: Wrong Answer

Solution code:
def unchi(x,m,n):
  r=x//m+x//n-x//(m*n)
  return r
a,b,c,d=(int(i) for i in input().split())
print(b-a+1-(unchi(b,c,d)-unchi(a-1,c,d)))

Submission status: Wrong Answer

Solution code:
a,b,c,d =(int(i) for i in input().split())  

import fractions

a1 = a//c
b1 = b//c

r1 = abs(a1-b1)

a2 = a//d
b2 = b//d
r2 = abs(a2-b2)

if a % c == 0:
	r1 += 1

#print(r1)
if a % d == 0:
	r2 += 1
#print(r2)

x = c*d/fractions.gcd(c, d)
p = b//x
q = a//x


r = abs(p - q)

if a % x == 0:
	r += 1

#print(r)
print(int((b-a)+1 -(r1 + r2 - r)))

Submission status: Wrong Answer

Solution code:
A, B, C, D = [int(i) for i in input().split()]

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a


countC = B // C - A // C
if A % C == 0:
    countC += 1
countD = B // D - A // D
if A % D == 0:
    countD += 1
s = gcd(C, D)
countCD = B // C // (D // s) - A // C // (D // s)
if A / C / (D // s) == 0:
    countCD += 1

print(B - A + 1 - countC - countD + countCD)

Submission status: Wrong Answer

Solution code:
import fractions
a, b, c, d = map(int, input().split())
if a==b:
  if a%c!=0 and a%d!=0:
    print(1)
  else:
    print(0)
else:
  cd = int(c*d/fractions.gcd(c, d))
  waru_c = int(b/c)-int((a-1)/c)
  waru_d = int(b/d)-int((a-1)/d)
  waru_cd = int(b/cd)-int((a-1)/cd)
  print((b-a+1)-(waru_c+waru_d-waru_cd))

Submission status: Wrong Answer

Solution code:
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

a, b, c, d = [int(elem) for elem in input().split()]
print((b+1 - a) - ((b+1) // c) - ((b+1) // d) + ((a-1) // c) + ((a-1) // d) + ((b+1) // lcm(c, d)) - ((a-1) // lcm(c, d)))

Submission status: Wrong Answer

Solution code:
import fractions

def fnc(start, end, divisor):
  return start % divisor > end % divisor

A, B, C, D = map(int, input().split())

rng = B - A + 1

Cmod = rng // C
if fnc(A+C*(rng // C), B, C):
  Cmod += 1

Dmod = rng // D
if fnc(A+D*(rng // D), B, D):
  Dmod += 1

lcm = C*D // fractions.gcd(C, D)
lcmod = rng // lcm
if fnc(A+lcm*(rng // lcm), B, lcm):
  lcmod += 1

print(rng - Cmod - Dmod+ lcmod)

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd


def read():
    A, B, C, D = list(map(int, input().strip().split()))
    return A, B, C, D


def solve(A, B, C, D):
    nC = math.floor(B / C) - math.ceil(A / C) + 1
    nD = math.floor(B / D) - math.ceil(A / D) + 1
    lcm = C * D // gcd(C, D)
    nCD = math.floor(B / lcm) - math.ceil(A / lcm) + 1
    return (B - A + 1) - (nC + nD - nCD)


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int, input().split())

k = B - A + 1

if A%C == 0:
    sc = B//C -A//C +1
else:
    sc = B//C -A//C

if A%D == 0:
    sd = B//D -A//D +1
else:
    sd = B//D -A//D    
    

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

cd = C*D/gcd(C,D)

if A%D == 0:
    scd = B//cd -A//cd +1
else:
    scd = B//cd -A//cd    

print(int(k + scd -sc -sd))

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return int(gcd(b, c))

def lcm(a, b):
    return int(a * b / gcd(a,b))

A, B, C, D = list(map(int, input().split(" ")))

l = lcm(C, D)

B = B+1
x = (B-A)
y = (B//C - A//C)
z = (B//D - A//D)
a = (B//l - A//l)
print(x+a - (y+z))

Submission status: Wrong Answer

Solution code:
import fractions
import math


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


a, b, c, d = map(int, input().split())

common = lcm(c, d)

div_c = math.floor(b / c) - math.ceil(a / c) + 1
div_d = math.floor(b / d) - math.ceil(a / d) + 1
div_common = math.floor(b / common) - math.ceil(a / common) + 1
print((b - a) + 1 - div_c - div_d + div_common)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
A -= 1
# A
Ax = A // (C * D)
Ay = A // C
Az = A // D
AA = Ay + Az -Ax
a = A - AA
# B
Bx = B // (C * D)
By = B // C
Bz = B // D
BB = By + Bz -Bx
b = B - BB

print(b - a)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
waric = 1 if A%C == 0 else 0
warid = 1 if A%D == 0 else 0
waricd = 1 if A%(C*D) == 0 else 0
cnd = B - A + 1 - (B//C - A//C + waric)
dnd = B - A + 1 - (B//D - A//D + warid) 
cdnd = B - A + 1 - (B//(C*D) - A//(C*D) + waricd)
print(cnd + dnd - cdnd)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a, b, c, d = map(int, input().split())

n = b - a + 1
x0 = (a - 1)// c
y0 = b // c
x1 = (a - 1) // d
y1 = b // d
x2 = (a - 1) // (c * d)
y2 = b // (c * d // gcd(c, d))

print(n - ((y0 - x0) + (y1 - x1) - (y2 - x2)))

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int, input().split())
A -= 1
if C % 2 == 0 and D % 2 == 0:
    X = B//(C*D//2) - A//(C*D//2)
else:
    X = B//(C*D) - A//(C*D)
cc = B//C - A//C
dd = B//D - A//D
print(B - A - cc - dd + X)

Submission status: Wrong Answer

Solution code:
import math
import fractions
a, b, c, d = list(map(int, input().split()))
e = round(c * d / fractions.gcd(c, d))

cko = math.floor(b/c) - math.ceil(a/c) + 1
dko = math.floor(b/d) - math.ceil(a/d) + 1
eko = math.floor(b/e) - math.ceil(a/e) + 1
print(b-a+1-cko-dko+eko)

Submission status: Wrong Answer

Solution code:
import fractions
A, B, C, D = (int(x) for x in input().split())

C_ = int(B/C) - int(A/C)
if A%C == 0:                                                                                                                                                                                                
    C_ += 1                                                                                                                                                                                                 
D_ = int(B/D) - int(A/D)
if A % D == 0:                                                                                                                                                                                              
    D_ += 1                                                                                                                                                                                                 

E = C * D / fractions.gcd(C, D)
E_ = int(B/E) - int(A/E)

ans = B - A + 1 - C_ - D_ + E_
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

def main():
    a,b,c,d = map(int,input().split(" "))
    n = b - a + 1

    noinclude = int((a-1)/c) + int((a-1)/d) - int((a-1)/(c * d / gcd(c, d)))
    include = int(b/c) + int(b/d) - noinclude - int(b/(c * d / gcd(c, d)))
    print(n - include)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
A,B,C,D = map(int,input().split())

def gcd(a,b):
	while b!=0:
		a,b=b,a%b
	return a


lcm_C_D = (C * D) // gcd(C, D)
rem_C = lcm_C_D // C
rem_D = lcm_C_D // D

lcm_count = rem_C + rem_D - 1


rem_A = A % lcm_C_D
dif_A = lcm_C_D - rem_A
count_A_C = dif_A // C
count_A_D = dif_A // D
before_count = count_A_C + count_A_D + 1



dif_B = B % lcm_C_D
count_B_C = dif_B // C
count_B_D = dif_B // D
after_count = count_B_C + count_B_D 


syou_A = (A + dif_A) // lcm_C_D
syou_B = (B - dif_B) // lcm_C_D
between_count = (syou_B - syou_A) * lcm_count


print(B - A + 1 - (after_count + between_count + before_count))

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())

n = b-a+1   # ここから，cまたはdで割り切れるものの個数を引く．
# cで割り切れる個数+dで割り切れる個数-c*dで割り切れる個数


if a%c==0:
    c1 = a//c   # 範囲に入っているのは，c*c1から
else:
    c1 = a//c + 1

c2 = b//c       #               c*c2まで．


if a%d==0:
    d1 = a//d
else:
    d1 = a//d + 1

d2 = b//d


if a%(c*d)==0:
    cd1 = a//(c*d)
else:
    cd1 = a//(c*d) + 1

cd2 = b//(c*d)



if c1<=c2:
    nc = c2-c1+1
else:
    nc = 0

    
if d1<=d2:
    nd = d2-d1+1
else:
    nd = 0
    

if cd1<=cd2:
    ncd = cd2-cd1+1
else:
    ncd = 0

# print(n,nc,nd,ncd)
print(n-nc-nd+ncd)

Submission status: Wrong Answer

Solution code:
from math import ceil,floor
A,B,C,D = map(int,input().split())

def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)

# aとbの最小公倍数
# a*b = lcm(a,b)*gcd(a,b) より
def lcm(a,b):
    return a*b//gcd(a,b)

def keisan(s,e,d):
    if s//d != e//d:
        if s%d == 0:
            return floor(e/d) - floor(s/d) + 1
        else:
            return floor(e/d) - floor(s/d)
    elif e-s < d:
        return 0
    else:
        return 1

print(B-A+1-(keisan(A,B,C)+keisan(A,B,D)-keisan(A,B,lcm(C,D))))

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
a,b,c,d = map(int,input().split())
import math
lcm = int(c*d/gcd(c,d))
a_1 = a-1
panish = (int(b/c)+int(b/d)-int(b/lcm))-((int(a_1/c)+int(a_1/d))-int(a_1/lcm))
print(b-a_1-panish)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

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

b_num = b - b//c - b//d + b//lcm
a_num = a - a//c - a//d + a//lcm

ans = b_num - a_num + 1

print(ans)

Submission status: Wrong Answer

Solution code:
def gcd(x,y):
    if y>x:
        a=y
        y=x
        x=a
    while y:
        a=x%y
        x=y
        y=a
    return x
a,b,c,d=map(int,input().split())
s=b-a+1
G=c*d//gcd(c,d)
print(s-(s+a%c)//c-(s+a%d)//d+(s+a%G)//G)

Submission status: Wrong Answer

Solution code:
import fractions

a,b,c,d = map(int,input().split())
#print(a,b,c,d)
gcd = fractions.gcd(c,d)
lcm = int(c*d / gcd)
#print(gcd,lcm)


c_div1 = int((a-1) / c)
c_div2 = int(b / c)
d_div1 = int((a-1) / d) 
d_div2 = int(b / d)
lcm_div1 = int((a-1) / lcm)
lcm_div2 = int(b / lcm)

ans = (c_div2 - c_div1) + (d_div2 - d_div1) - (lcm_div2 - lcm_div1)
#print(c_div1,c_div2,d_div1,d_div2,lcm_div1,lcm_div2)
print(b - a - ans + 1)

Submission status: Wrong Answer

Solution code:
#最大公約数
def gcd(a,b):
    while b:
        a,b = b,a%b
    return a
#最小公倍数
def lcm(x,y):
    return (x*y//gcd(x,y))


A,B,C,D = map(int,input().split())
CDlcm = lcm(C,D)

c = (B+1)//C-A//C

d = (B+1)//D-A//D

e = (B+1)//CDlcm-A//CDlcm

print((B-A+1)-c-d+e)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int, input().split())
print(b-a+1 - ((b-a+1)//c + (b-a+1)//d - (b-a+1)//(c*d)))

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
e=(b-a+1)//c
f=(b-a+1)//d 
g=(b-a+1)//(c*d)
ans=(b-a+1)-(e+f-g)
print(ans)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
    
def lcm(x, y):
    return (x * y) // gcd(x, y)


A, B, C, D = map(int, input().split())
target = B - A + 1

hoge1 = int(B / C) - int((A - 1) / C)
hoge2 = int(B / D) - int((A - 1) / D)
hoge3 = int(B / (C * D)) - int((A - 1) / (C * D))

saisho = lcm(C, D)
hoge4 = B // saisho - (A - 1) // saisho

print(target - hoge1 - hoge2 + hoge4)

Submission status: Wrong Answer

Solution code:
import math
import fractions
a,b,c,d=list(map(int,input().split()))
a-=1
s=math.floor(b/c)-math.floor(a/c)
e=math.floor(b/d)-math.floor(a/d)
count=b-a-s-e
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
    #return math.floor((x * y) /fractions.gcd(x, y))


com=lcm(c, d)
tmp=math.floor(b/com)-math.floor(a/com)
print(count+tmp)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd (a, b)

A, B, C, D = map(int, input().split())

a = int((A - 1) / C)
b = int(B / C)

c = int((A - 1) / D)
d = int(B / D)

l = lcm(C, D)

e = int((A - 1) / l)
f = int(B / l)

res = (B - A + 1) - ((b - a) + (d - c)) + (f - e)

print(res)

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())

sub = B - A + 1
cDivNum = int(sub // C)
dDivNum = int(sub // D)
cdDivNum = int(sub // (C*D))

#print(sub,cDivNum,dDivNum,cdDivNum)
print(sub - (cDivNum+dDivNum-cdDivNum))

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a*b//gcd(a, b)


a, b, c, d = map(int, input().split())

first_c = c * a // c + a % c
last_c = c * b // c
first_d = d * a // d + a % d
last_d = d * b // d
cd = lcm(c, d)
first_cd = cd * a // cd + a % cd
last_cd = cd * b // cd

cnum = (last_c - first_c) // c + 1
dnum = (last_d - first_d) // d + 1
cdnum = (last_cd - first_cd) // cd + 1

total = cnum + dnum - cdnum
print(b - a + 1 - total)

Submission status: Wrong Answer

Solution code:
import math

A , B , C , D = map(int,input().split())

if C > D :
    C , D = D , C

ans = 0

if A < C :
    ans += C - A
    A = C

# A以上B以下の数でXの倍数の個数
def countX(X) :
    if X >= B :
        return 0
    minX = math.ceil(A / X)
    maxX = math.floor(B / X)

    return maxX - minX

ans += B - A - countX(C) - countX(D) + countX(C * D)

print(ans)

Submission status: Wrong Answer

Solution code:
import math

#n = int(input())
a, b, c, d = [int(i) for i in input().split()]
#table = [[int(i) for i in input().split()] for j in range(n)]
#table = [list(input()) for n in range(h)]
#list = [int(i) for i in input().split()]
#num = [int(i) for i in range(n)]
#s = input()
#list = list(s)

kotae = 0
temp = 0

def gcd(a, b):
    while b != 0:
        temp = a
        a = b
        b = temp % b
    return a


kaisic = int(a / c)
owaric = int(b / c)
kaisid = int(a / d)
owarid = int(b / d)
e = c * d / gcd(c, d)
kaisie = int(a / (e))
owarie = int(b / (e))

countc = owaric - kaisic + 1
if (kaisic * c != a) :
    countc -= 1

countd = owarid - kaisid + 1
if (kaisid * d != a) :
    countd -= 1

counte = owarie - kaisie + 1
if (kaisie * e != a) :
    counte -= 1


print(b - a + 1 - (countc + countd - counte))