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:

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

def c(begin, end, num):
    r = end - begin + 1
    if r < num:
        if begin < num < end:
            return 1
        else:
            return 0
    if num == r:
        return 1
    if num < r:
        while begin % num != 0:
            begin += 1
        begin += 1
        r = end - begin + 1
        return 1 + (r // num)

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

C, D = (C, D) if C < D else (D, C)
CD = (C * D) // gcd(C, D)

count = 0

if C == D:
    c_count = c(A, B, C)
    count = c_count
elif D == CD:
    c_count = c(A, B, C)
    d_count = c(A, B, D)
    count = c_count + d_count
else:
    c_count = c(A, B, C)
    d_count = c(A, B, D)
    cd_count = c(A, B, CD)
    count = c_count + d_count - cd_count

print((B - A + 1) - count)

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(a, b):
	return a * b // gcd (a, b)

bb = b-int(b/c)-int(b/d)+int(b/lcm(c,d))   
aa = (a-1)-int((a-1)/c)-int((a-1)/d)+int((a-1)/lcm(c,d))
print(bb-aa)

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D = map(int, input().split())
x = abs(A-B)//C + 1
y = abs(A-B)//D + 1
if abs(A-B)//((C*D)//fractions.gcd(C,D)) == 0:
    z = 0
else:
    z = abs(A-B)//((C*D)//fractions.gcd(C,D)) + 1
print(B-A+1-x-y+z)

Submission status: Wrong Answer

Solution code:
from math import ceil
def gcd(a, b):
	if b==0:
		return a
	else:
		return gcd(b, a%b)
def lmc(a, b):
	return a*(b//gcd(a, b))

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

l = ceil(a/c)*c
r = (b//c)*c
k1 =(r-l)//c+1

l = ceil(a/d)*d-1
r = (b//d)*d
k2 =(r-l)//d+1

w = lmc(c, d)
l = ceil(a/w)*w-1
r = (b//w)*w
k3 =(r-l)//w+1

ans = (b-a+1)-(k1+k2-k3)
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from fractions import gcd
A, B, C, D = [int(_) for _ in stdin.readline().rstrip().split()]
inclusive = B-A+1
mul_C = (B-A)//C+1
mul_D = (B-A)//D+1
lcm_CD = C * D // gcd(C, D)
mul_CD = (B-A)//lcm_CD+1
print(inclusive-mul_C-mul_D+mul_CD)

Submission status: Wrong Answer

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

cou1=0
cou2=0

y1=int(b/c)
y2=int(b/d)
y3=int(b/lcm)
cou1=b-(y1+y2-y3)

if a!=1:
    x1=int((a-1)/c)
    x2=int((a-1)/d)
    x3=int((a-1)/lcm)
    cou2=(a-1)-(x1+x2-x3)
if a==1:
    cou2=0

print(cou1-cou2)

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)
e=(s%c>a%c)+(s%d>a%d)-(s%G>a%G)
print(s-s//c-s//d+s//G-e)

Submission status: Wrong Answer

Solution code:
import fractions

def antidiv(x,l,c,d):
    if x == l:
        return l - (l // c) - (l // d) + 1
    else:
        return x - (x // c) - (x // d) 

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

l = (c*d)//fractions.gcd(c,d)


aq = a // l
ar = a % l
bq = b // l
br = b % l
#print(br)

qq = bq - aq - 1
r1 = antidiv(l,l,c,d) - antidiv(ar-1,l,c,d)
r2 = antidiv(br,l,c,d)

if br != 0:
    ans = qq * antidiv(l,l,c,d) + r1 + r2
else:
    ans = (qq+1) * antidiv(l,l,c,d) + r1 + r2

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions


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


abcd = input().split(" ")
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])
cd = lcm(c, d)

print(b-a+1 - ((b+1)//c - a//c) - ((b+1)//d - a//d) + ((b+1)//cd - a//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()]

res = (b+1 - a) - ((b+1) // c) - ((b+1) // d) + (a // c) + (a // d) + ((b+1) // lcm(c, d)) - (a // lcm(c, d))
if a % c == 0 or a % d == 0:
    res -= 1
print(res)

Submission status: Wrong Answer

Solution code:
import math
import fractions
import numpy as np

def gcd_strategy():
    return math.gcd if hasattr(math, "gcd") else fractions.gcd

gcd = gcd_strategy()

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

# %%
A, B, C, D = list(map(int, input().split()))
    
CD = lcm(C, D) 

n_C = int(np.floor(B/C) - np.floor((A-1)/C))
n_D = int(np.floor(B/D) - np.floor((A-1)/D))

n_CD = int(np.floor(B/CD) - np.floor((A-1)/CD))

print('{}'.format(B-A+1-(n_C+n_D-n_CD)))

Submission status: Wrong Answer

Solution code:
import math

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

# Cで割り切れる数
div_c_min = math.ceil(A/C)
div_c_max = math.floor(B/C)
div_c_num = div_c_max - div_c_min + 1
#print(div_c_min, div_c_max)
#print(div_c_num)

# Dで割り切れる数
div_d_min = math.ceil(A/D)
div_d_max = math.floor(B/D)
div_d_num = div_d_max - div_d_min + 1
#print(div_d_min, div_d_max)
#print(div_d_num)

# 最大公約数
def gcd(m, n):
  x = max(m, n)
  y = min(m, n)
  while x%y != 0:
    z = x % y
    x = y
    y = z
  else:
    return y

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

# CとDの公倍数で割り切れる数
div_cd_min = math.ceil(A / lcm(C, D))
div_cd_max = math.floor(B / lcm(C, D))
div_cd_num = div_cd_max - div_cd_min + 1
#print(div_cd_min, div_cd_max)
#print(div_cd_num)

numAtoB = B - A + 1
print(numAtoB - (div_c_num + div_d_num - div_cd_num))

Submission status: Wrong Answer

Solution code:
import fractions
A, B, C, D=list(map(int, input().split()))
counter = 0
lcm = (C*D)/fractions.gcd(C,D)
cda = int((A-1)/C)
dda = int((A-1)/D)
cdb = int(B/C)
ddb = int(B/D)
cdda = int((A-1)/lcm)
cddb = int(B/lcm)
counter = (cdb - cda) + (ddb - dda) - (cddb -cdda)
print(B+1-A-counter)

Submission status: Wrong Answer

Solution code:
# n = int(sys.stdin.readline())
# a, b = map(int, sys.stdin.readline().split())
# c = list(map(int, sys.stdin.readline().split()))
# s = [list(map(int,list(sys.stdin.readline()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a = 100
# b = 0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋め, 小数点出力桁指定時のときの出力
# 000100-0.987654

import math
import sys
import itertools
import queue

mod = 1000000007

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

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

if __name__ == "__main__":
    A, B, C, D = map(int, sys.stdin.readline().split())
    A = A - 1
    c_div = math.floor(B / C)
    #nc_div = (B - c_div)
    d_div = math.floor(B / D)
    #nd_div = (B - d_div)
    cd_div = math.floor(B / lcm(C, D))
    #ncd_div = (B - cd_div)
    #print(nc_div)
    #print(nd_div)
    #print(ncd_div)


    not_div1 = B - (c_div + d_div -cd_div)

    c_div = math.floor(A / C)
    nc_div = (A - c_div)
    d_div = math.floor(A / D)
    nd_div = (A - d_div)
    cd_div = math.floor(A / lcm(C, D))
    ncd_div = (A - cd_div)

    not_div2 = A - (c_div + d_div -cd_div)
    #not_div2 = nc_div + nd_div - ncd_div

    #print(not_div1)
    #print(not_div2)

    #print(not_div2)

    print(not_div1 - not_div2)

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())

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

CD = int(C * D / gcd(C, D))
cd = int(B/CD) - int((A-1)/CD)

ans = B - (A-1) - (c + d - cd)
print(ans)

Submission status: Wrong Answer

Solution code:
def gcd(c,d):
    #c<d
    if d%c == 0:
        return int(c)
    else:
        return gcd(d%c,c)

def main():
    a,b,c,d=map(int,input().split(' '))
    c,d=sorted([c,d])
    lmc = c*d/gcd(c,d)
    e = a-1
    print(int((b-a+1)-(b//c + b//d - b//lmc -1*(e//c + e//d - e//lmc))))

main()

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

if a_num == 0:
    ans = b_num
else:
    ans = b_num - a_num + 1

print(ans)

Submission status: Wrong Answer

Solution code:
#c.py
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
def lcm(a, b):
    return a * b / gcd(a,b)
a,b,c,d = map(int,input().split())
canC = int(b//c - (a-1)//c)
canD = int(b//d - (a-1)//d)
dbCD = int(b//lcm(c,d) - (a-1)//lcm(c,d))
print((b-a+1) -canC - canD + dbCD)
#print(int((b-a+1)-((b//c + b//d - b//lcm(c,d))-((a-1)//c + (a-1)//d) - (a-1)//lcm(c,d))))

Submission status: Wrong Answer

Solution code:
import fractions

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

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

E = lcm(C, D)

val1 = A // C
val2 = B // C
val3 = A // D
val4 = B // D
val5 = A // E
val6 = B // E

s = B - A + 1

print(s - (val2 - val1 + val4 - val3 - (val6 - val5)))

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
cnt = 0
tmp = d
f = False
while tmp < b:
    if tmp % c == 0:
        f = True
        break
    tmp += d

v1 = b//c - (a-1)//c
v2 = b//d - (a-1)//d
v3 = b//tmp - (a-1)//tmp if f else 0
print(b-a+1-v1-v2+v3)

Submission status: Wrong Answer

Solution code:
import fractions, math
A, B, C, D = map(int, input().split())
U = B - A + 1

MofD = 0
MofCD = 0

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


def sten(st, en, x):
    st = math.ceil(st/x)*x
    en = math.floor(en/x)*x
    if en >= st:
        n = (en - st) // x + 1
    else:
        n = 0
    return n


MofC = sten(A, B, C)
if C != D:
    MofD = sten(A, B, D)
    MofCD = sten(A, B, lcm(C, D))

print(U-MofC-MofD+MofCD)

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())
if A%C==0 and A%D==0:
    C_div = (B-A+1)//C + 1
else:
    C_div = (B-A+1)//C
if B%C==0 and B%D==0:
    D_div = (B-A+1)//D + 1
else:
    D_div = (B-A+1)//D
if A%(C*D) == 0 and B%(C*D) == 0:
    CD_div = (B-A+1)//(C*D) + 1
else:
    CD_div = (B-A+1)//(C*D)
if C == 1 or D == 1:
    print(0)
elif C == D:
    print((B-A+1) - C_div)
else:
    print((B-A+1) - C_div -D_div + CD_div)

Submission status: Wrong Answer

Solution code:
import fractions
a, b, c, d = map(int, input().split())
e = c*d//fractions.gcd(c,d)
s = b-a+1
cb = b//c
db = b//d
eb = b//e
ca = a//c
da = a//d
ea = a//e
print(int(s - (cb - ca + db -da - eb + ea)))

Submission status: Wrong Answer

Solution code:

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

def c(begin, end, num):
    r = end - begin + 1
    if r < num:
        if begin < num < end:
            return 1
        else:
            return 0
    if num == r:
        return 1
    if num < r:
        while begin % num == 0:
            begin += 1
        begin += 1
        r = end - begin + 1
        return 1 + r // num

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

C, D = (C, D) if C < D else (D, C)
CD = (C * D) // gcd(C, D)

count = 0

c_count = c(A, B, C)
d_count = c(A, B, D)
cd_count = c(A, B, CD)

if C == D:
    count = c_count
elif D == CD:
    count = c_count + d_count
else:
    count = c_count + d_count - cd_count

print((B - A + 1) - count)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
a,b,c,d=list(map(int,input().split(" ")))
g=gcd(c,d)
cd=c*d
Ncd=int(b/(cd/g))-int(a/(cd/g))
Nc=int(b/c)-int(a/c)
Nd=int(b/d)-int(a/d)
print(b-a+1-(Nc+Nd-Ncd))
print(Nc,Nd,Ncd)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
import fractions
A, B, C, D = map(int, input().split())

num_div_C = math.floor(B / C) - math.floor(A / C)
num_div_D = math.floor(B / D) - math.floor(A / D)
lcm = C * D // fractions.gcd(C, D)
num_div_CD = math.floor(B / lcm) - math.floor(A / lcm)

print(B - A + 1 - (num_div_C + num_div_D - num_div_CD))

Submission status: Wrong Answer

Solution code:
A, B, C, D =  (int(j) for j in input().split()) 
    
n = B - A + 1
CD = C * D
if C != D:
  print( n- ( (B//C - (A-1)//C) + (B//D - (A-1)//D) - (B//CD - (A-1)//CD) ) )
else:
  print( n- ( (B//C - (A-1)//C) ) )

Submission status: Wrong Answer

Solution code:
def gcd(x, y):
    while y > 0:
        x, y = y, x%y
    return x

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

a, b, c, d = map(int, input().split())
hoge =  int((b - a)/c)
hoge2 = int((b - a)/d)
hoge3 = int(int(b - a)/int(lcm(c, d)))
print((b - a) - (hoge + hoge2 - hoge3))

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())

c1 = int((B - B%C)/C) - int(((A-1) - (A-1)%C)/C)
d1 = int((B - B%D)/D) - int(((A-1) - (A-1)%D)/D)

CD = int((C * D - C * D % gcd(C, D)) / gcd(C, D))
cd1 = int((B - B%CD)/CD) - int(((A-1) - (A-1)%CD)/CD)

ans = B - (A-1) - (c1 + d1 - cd1)
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d=map(int,input().split())
m = c* d / fractions.gcd(c,d)
print(m)
x=0
x=(b-a+1)-((b//c-a//c)+(b//d-a//d)-(b//m-a//m))
print(int(x))

Submission status: Wrong Answer

Solution code:
def saidaikouyaku(a, b):
    if b > a:
        a, b = b, a

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

A, B, C, D = map(int, input().split())
amari1 = 0
amari2 = 0
amari3 = 0
hani = B - A + 1
if B > C:
    amari1 = A % C
F = hani + amari1
Cnum = int(F / C)
if B > D:
    amari2 = A % D
G = hani + amari2
Dnum = int(G / D)
saisyoukoubai = int(C * D / saidaikouyaku(C, D))
if B > saisyoukoubai:
    amari3 = A % saisyoukoubai
H = hani + amari3
koubainum = int(H / saisyoukoubai)
#print(Cnum, Dnum, koubainum)
print(hani - Cnum - Dnum + koubainum)

Submission status: Wrong Answer

Solution code:
#S=input()
import fractions

lis=list(map(int,input().split()))
gCD=fractions.gcd(lis[2],lis[3])
CD=int(lis[2]*lis[3]/gCD)
AmodC=lis[0]%lis[2]
if AmodC==0:
    AC=lis[0]
else:
    AC=lis[0]+(lis[2]-AmodC)
AmodD=lis[0]%lis[3]
if AmodD==0:
    AD=lis[0]
else:
    AD=lis[0]+(lis[3]-AmodD)
BC=lis[1]-lis[1]%lis[2]
BD=lis[1]-lis[1]%lis[3]
AmodCD=lis[0]%CD
if AmodCD==0:
    ACD=lis[0]
else:
    ACD=lis[0]+(CD-AmodCD)
BCD=lis[1]-lis[1]%CD
ABC=(BC-AC)/lis[2]+1
ABD=(BD-AD)/lis[3]+1
ABCD=(BCD-ACD)/CD+1
ans=lis[1]-lis[0]+1-int(ABC+ABD-ABCD)

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math
import fractions

A, B, C, D = list(map(int, stdin.readline().split()))
cd = C * D // fractions.gcd(C,D)

Nc = B // C - math.ceil(A / C) + 1
Nd = B // D - math.ceil(A / D) + 1
Ncd = B // cd - math.ceil(A / cd) + 1

print(B-A+1-(Nc+Nd-Ncd))

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 = int(C * D / int(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

if A == B:
  if A % C == 0 or A % D == 0:
    print(0)
  else:
    print(1)
else:
  print(B - A + 1 - k5 - k6 + k9)

Submission status: Wrong Answer

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

if a%c==0:
    cc=int(b/c)-int(a/c)
else:
    cc = int(b / c) - (int(a / c)+1)


if a%d==0:
    dd = int(b / d) - int(a / d)
else:
    dd=int(b/d)-int((a/d)+1)

i=0
f=[c]
x=8
k=[c,d]

while x!=0:
    x=max(k)%min(k)

    if x!=0:
        f.append(x)
    k.sort()
    k[1]=x
#Wprint(min(f))

if a%d==0:
    cd = int(b / (c*d/min(f)))- int(a / (c*d/min(f)))
else:
    cd=int(b/(c*d/min(f)))-(int(a/(c*d/min(f)))+1)


print(b-a-cc-dd+cd)

Submission status: Wrong Answer

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

i = 1
cCnt =0
while A + C*i <= B:
    i = i+1
    cCnt =cCnt+1

i = 1
dCnt =0
while A + D*i <= B:
    i = i+1
    dCnt =dCnt+1

i = 1
cdCnt =0
while A + C*D*i <= B:
    i = i+1
    cdCnt =cdCnt+1

print(B-A-cCnt-dCnt+cdCnt)

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

if A == B :
    if A % C == 0 or A % D == 0 :
        print(0)
    else :
        print(1)
else :
    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 + 1

    # 最小公倍数
    Z = C * D / fractions.gcd(C,D)

    ans += B - A + 1 - countX(C) - countX(D) + countX(Z)

    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

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

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

if b_num == 0 and a_num == 0:
    ans = 0
else:
    ans = b_num - a_num + 1

print(ans)

Submission status: Wrong Answer

Solution code:
# C
def gcd(a,b):
    if a<b: a,b = b,a
    r = a % b
    while(r!=0):
        a,b = b,r
    return b

# 1からNでs,tで割れないもの
def nonDivided(n,s,t):
    if not n > 0:
        return 0
    else:
        return n-int(n/s)-int(n/t)+int(n*gcd(s,t)/(s*t))

if __name__=='__main__':
    a,b,c,d = map(int,input().split())
    print(nonDivided(b,c,d)-nonDivided(a-1,c,d))

Submission status: Wrong Answer

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

def euc(a,b):
    x = a*b
    if(a<b):
        t = b
        b = a
        a = t
    
    r = a%b
    while(r!=0):
        a = b
        b = r
        r = a%b
    
    return int(x/b)

if(C % D == 0):
    w = D
elif(D % C == 0):
    w = C
else:
    w = euc(C,D)
    
nc = int(B/C)-int((A-1)/C)
nd = int(B/D)-int((A-1)/D)
ncd = int(B/w)-int((A-1)/w)

n = nc + nd - ncd

print(B-A +1 -n)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import random
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def main():

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

	E = lcm(C, D)
	if C == D:
		tmp_C2 = B // C
		tmp_C2ama = B % C

		tmp_C1 = A // C
		tmp_C1ama = A % C

		tmp = (tmp_C2-tmp_C1)

		tmp2 = 0
		if tmp_C1ama == 0:
			tmp2 -=1

		ans = B-A-tmp+1+tmp2
		print(ans)
		sys.exit()
		





	tmp_C2 = B // C
	tmp_C2ama = B % C
	tmp_D2 = B // D
	tmp_D2ama = B % D
	tmp_C1 = A // C
	tmp_C1ama = A % C
	tmp_D1 = A // D
	tmp_D1ama = A % D

	tmp_E2 = B // E
	tmp_E2ama = B % E
	tmp_E1 = A // E
	tmp_E1ama = A % E

	#print(tmp_C2)

	tmp = (tmp_C2+tmp_D2)-(tmp_C1+tmp_D1)

	tmp2 = 0
	if tmp_C1ama == 0:
		tmp2 -=1
	if tmp_D1ama == 0:
		tmp2 -=1
	#print(tmp2)

	ans = B-A-tmp+1+(tmp_E2-tmp_E1)+tmp2

	print(ans)

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

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

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
gene = b-a+1
def gcd(x,y):
    X = max(x,y)
    Y = min(x,y)
    if Y == 0:
        return X
    else:
        return gcd(Y,X%Y) 
if c != d:
    if ((b % c == 0) ^ (b % d == 0)) and ((a % c == 0) ^ (a % d == 0)) :
        print(gene - (gene // c +gene // d - gene // (c*d//gcd(c,d))))
    else:
        print(gene - (gene // c +gene // d - gene // (c*d//gcd(c,d)))-1)

Submission status: Wrong Answer

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

lst = []
for i in range(A, B+1):
    if (i % C != 0) and (i % D != 0):
        lst.append(i)
print(len(lst))

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())
b = B - int(B/C) - int(B/D) + int(B/((C*D)/gcd(C,D)))
a = (A-1) - int((A-1)/C) - int((A-1)/D) + int((A-1)/((C*D)/(gcd(C,D))))
print(b-a)

Submission status: Wrong Answer

Solution code:
def floor(a, b):
  return int((a - a%b)/b)
def gcd(a, b):
  while b != 0:
      a, b = b, a % b
  return a
def lcm(a, b):
  return (a * b) // gcd(a, b)
input = list(map(int, input().split(' ')))
total_count = input[1] + 1 - input[0]
div_c = floor(input[1], input[2]) - floor(input[0], input[2])
if input[0] % input[2] == 0:
  div_c += 1
div_d = floor(input[1], input[3]) - floor(input[0], input[3])
if input[0] % input[3] == 0:
  div_d += 1
div_cd = floor(input[1], lcm(input[2], input[3])) - floor(input[0], lcm(input[2], input[3]))
if input[0] % lcm(input[2], input[3]) == 0:
  div_cd += 1
print(total_count - (div_c + div_d - div_cd))

Submission status: Wrong Answer

Solution code:
def main():
    A,B,C,D=input().split()
    A=int(A)
    B=int(B)
    C=int(C)
    D=int(D)
    C_min=A-A%C+C
    C_max=B-B%C
    D_min=A-A%D+D
    D_max=B-B%D
    CD_min=A-A%(C*D)
    CD_max=B-B%(C*D)
    C_sum=(C_max-C_min)/C+1
    D_sum=(D_max-D_min)/D+1
    CD_sum=(CD_max-CD_min)/(C*D)+1
    sum= B-A+1-(C_sum+D_sum-CD_sum)
    return sum

sum=main()
print(sum)

Submission status: Wrong Answer

Solution code:
A , B , C , D = map(int, input().split())
hani = B - A + 1
if C == 1:
    Cdiv = hani
else:
    Cdiv = (B + 1) // C - A // C
if D == 1:
    Ddiv = hani
else:
    Ddiv = (B + 1) // D - A // D
def gcd(x, y):
    if x < y:
        tmp = x
        x = y
        y = tmp
    r = x % y   
    while r != 0:
        x = y
        y = r
        r = x % y
    return y
LCM = (C * D) // gcd(C, D)
if LCM == 1:
    LCMdiv = hani
else:
    LCMdiv = (B + 1) // LCM - A // LCM
ans = hani - Cdiv - Ddiv + LCMdiv
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions, math
A, B, C, D = map(int, input().split())
U = B - A + 1


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


def sten(st, en, x):
    st = math.ceil(st/x)*x
    en = math.floor(en/x)*x
    if en >= st:
        n = (en - st) // x + 1
    else:
        n = 0
    return n


MofC = sten(A, B, C)
MofD = sten(A, B, D)
MofCD = sten(A, B, lcm(C, D))

print(U-MofC-MofD+MofCD)

Submission status: Wrong Answer

Solution code:
import fractions

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

a1 = a // c
a2 = b // c
a3 = a2 - a1

b1 = a // d
b2 = b // d
b3 = b2 - b1 

x = c * d // fractions.gcd(c, d)

x1 = a // x
x2 = b // x
x3 = x2 - x1

p = b - a + 1
q = a3 + b3 - x3

print(p - q)

Submission status: Wrong Answer

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

e = b // c #c de wareru
f = a // c
g = e - f

h = b // d
i = a // d
j = h - i

import fractions

cd = c*d / fractions.gcd(c,d)

k = b // cd
l = a // cd
m = k -l

ans = (b-a) - (g + j - m) + 1
print(ans)

Submission status: Wrong Answer

Solution code:
RangeMin, RangeMax, valA, valB = map(int, input().split())

RangeMin -= 1
valC = valA * valB
ansList = []

for Range in [RangeMin, RangeMax] :
  ans1 = 0
  ans1 += Range // valA
  ans1 += Range // valB
  ans1 -= Range // valC
  ansList.append(ans1)

ans = ansList[1] - ansList[0]
ans = RangeMax - RangeMin - ans

print(ans)

Submission status: Wrong Answer

Solution code:
#https://atcoder.jp/contests/abc131/tasks/abc131_c

'''
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
'''
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 = [int(i) for i in input().split()]
C = 0
D = 0
E = 0
'''
for i in range(int(a / max(c,d,lcm(c,d))),b-a):
    print(i)
    if c * i >= a and c * i <= b and C == 0:
        C = c * i
    if d * i >= a and d * i <= b and D == 0:
        D = d * i
    if lcm(c,d) * i >= a and lcm(c,d) * i <= b and E == 0:
        E = lcm(c,d) * i
    if C != 0 and D != 0 and E != 0:
        break
'''
for i in range(int(a / lcm(c,d)),int(b / lcm(c,d))+1):
    if lcm(c,d) * i >= a and lcm(c,d) * i <= b and E == 0:
        E = lcm(c,d) * i
        break

for i in range(int(a / c),int(b / c)+1):
    if c * i >= a and c * i <= b and C == 0:
        C = c * i
        break

for i in range(int(a / d),int(b / d)+1):
    if d * i >= a and d * i <= b and D == 0:
        D = d * i
        break
#print(lcm(c,d))
#print('')
#print(C,D,E)
c2 = int(b / c) - int(C / c)+1
d2 = int(b / d) - int(D / d)+1
e2 = int(b / lcm(c,d)) - int(E / lcm(c,d))+1
#print(b-a+1,c2,d2,e2)
'''
c1 = list(range(C,b+1,c))
d1 = list(range(D,b+1,d))
e1 = list(range(E,b+1,lcm(c,d)))
print(b-a+1,len(c1),len(d1),len(e1))

print(c1,d1,e1)

print(b-a+1-len(c1)-len(d1)+len(e1))
'''
print(int(b-a+1 - c2 - d2 + e2))

Submission status: Wrong Answer

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

def c_in_a2b(c):
    return (B//c - A//c)
print((B-A+1)- c_in_a2b(C)-c_in_a2b(D)+c_in_a2b(C*D))

Submission status: Wrong Answer

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

sma=min(c,d)
big=max(c,d)

while sma!=0 :
    cal=big%sma
    big=sma
    sma=cal

euc=big
ggg=c*d//euc

#print(euc,ggg)

def  cnt(n,ggg,c,d):
    exc=ggg//c + ggg//d
    if c<ggg or d<ggg:
        exc-=1
    ret=exc*(n//ggg)
    #print(ggg,exc,ret)
    remain=n%ggg
    ret+= remain//c + remain//d
    return ret

#print(cnt(b,ggg,c,d))
#print(cnt(a-1,ggg,c,d))

jog=cnt(b,ggg,c,d)-cnt(a-1,ggg,c,d)

ans=(b-a+1)-jog

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
from math import ceil, floor
def lcm(x, y):
  return (x * y) // fractions.gcd(x, y)

A,B,C,D = map(int, input().split())
n = B-A+1
r = int(floor(B/C) - ceil(A/C) + 1) +\
    int(floor(B/D) - ceil(A/D) + 1) -\
    int(floor(B/lcm(C,D)) - ceil(A/lcm(C,D)) + 1)
print(n-r)

Submission status: Wrong Answer

Solution code:
str = input().split(" ")
a=int(str[0])
b=int(str[1])
c=int(str[2])
d=int(str[3])
count = 0
for i in range(a, b):
    if not i % c is 0 and not i % d is 0:
        count += 1
print(count)

Submission status: Wrong Answer

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


def solve(a, b, c, d):
    def how_many(to, divide):
        if to >= divide:
            n = to // divide
        else:
            n = 0
        return n
    count_by_c = how_many(b, c) - how_many(a - 1, c)
    count_by_d = how_many(b, d) - how_many(a - 1, d)
    count_by_cd = how_many(b, c * d) - how_many(a - 1, c * d)
    if count_by_c == 0 and count_by_d == 0 and  count_by_cd ==0:
        return 0
    result = b - a + 1 -(count_by_c + count_by_d - count_by_cd)
    # print(count_by_c,  count_by_d, count_by_cd)

    # print(result)
    return result

def main():
    a, b, c, d = input_from_console()
    print(solve(a, b, c, d))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()

Submission status: Wrong Answer

Solution code:
import sys,fractions
input = sys.stdin.readline

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


lcm =  (C*D)//fractions.gcd(C,D)
c=0
End = (B//C)+(B//D)-(B//(lcm))
if A != 1:
  Start = ((A-1)//C)+((A-1)//D)-((A-1)//(lcm))
else :
  Start = 1
print(int((B-A+1)-(End-Start)))

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 gcd(b, c)
def lcm(a,b):
    return int(a * b / gcd(a, b))
a, b, c, d = map(int, input().split())
b1 = b // c
a1 = a // c
b2 = b // d
a2 = a // d
a3 = a // lcm(c,d)
b3 = b // lcm(c,d)
a_ans = a1 + a2 - a3
b_ans = b1 + b2 - b3
diff = b - a
ans = diff - (b_ans - a_ans)
if (lcm(a,b) != a*b):
    ans += 1
print(ans)

Submission status: Wrong Answer

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

import fractions
import math

x = int(int(b//c) - int(math.ceil(a/c)) + 1)
y = int(int(b//d) - int(math.ceil(a/d)) + 1)
e = int(int(c*d)//int(fractions.gcd(c,d)))
z = int(int(b//e) - int(math.ceil(a/e)) + 1)

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

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
a1 = 0
a2 = 0
a1 = a + a%c
a2 = a + a%d
print(b-a-(int((b-a1)/c)+int((b-a2)/d)))

Submission status: Wrong Answer

Solution code:
def main():
    A,B,C,D=input().split()
    A=int(A)
    B=int(B)
    C=int(C)
    D=int(D)
    C_min=A-A%C+C
    C_max=B-B%C
    D_min=A-A%D+D
    D_max=B-B%D
    CD_min=A-A%(C*D)
    CD_max=B-B%(C*D)
    C_sum=(C_max-C_min)/C+1
    D_sum=(D_max-D_min)/D+1
    CD_sum=(CD_max-CD_min)/(C*D)+1
    sum= B-A+1-(C_sum+D_sum-CD_sum)
    return sum

sum=main()
sum_down=sum-sum%(10**8)
print(str(int(sum_down/10**8))+str(int(sum%(10**8))))

Submission status: Wrong Answer

Solution code:
import fractions

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


#A-BまでのCの個数

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

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

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

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