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:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

import numpy as np
import sys
import collections
import scipy.misc
import math
from operator import itemgetter
import itertools
import copy
import bisect
import fractions

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]
    

"""
N, X = map(int, input().split())

x = list(map(int, input().split()))

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

# 多次元配列の宣言（あとでintにすること。）（タプルにすること。）
dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)

#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]

#Distance Transformation
    for h in range(0,H):
        for w in range(0,W):
            if h == 0 and w == 0:
                pass
            elif h == 0:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h-1][W-w]+1)
            elif w == 0:   
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1)
            else:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1, D[H-h-1][W-w]+1, D[H-h][W-w]+2)
            d_max = max(D[H-h-1][W-w-1], d_max)

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


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

    
def main():
    res = 0
    tmp = 0
    if A%C == 0:
        tmp+=1    
    NC = B//C - A//C + tmp
    
    tmp = 0
    if A%D == 0:
        tmp+=1


    ND = B//D - A//D + tmp
    
    tmp=0
    lcm_CD =lcm(C, D)

    if A%lcm_CD == 0:
        tmp+=1
    lcm_CD =lcm(C, D) +tmp
    
    NCD= B//lcm_CD - A//lcm_CD 
    res = B-A+1 -(NC+ND-NCD)
    #print(NC, ND, NCD)        
        
        
        
    
    print(res)
                
                
                
            
            
                

    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# 2019/06/22
# AtCoder Beginner Contest 131 - C

import fractions
# Least Common Multiple
def lcm_fgf(a, b):
    return int(a * b / fractions.gcd(a, b))

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

clist = list()
dlist = list()
cdlist = list()

cd = lcm_fgf(c, d)

# wkc = (a // c) * c
# wkd = (a // d) * d
# wkcd = (a // cd) * cd

wkccnt = (b - a + 1) // c
wkdcnt = (b - a + 1) // d
wkcdcnt = (b - a + 1) // cd
rem1 = (b - a + 1) % c
rem2 = (b - a + 1) % d

candiv = wkccnt + wkdcnt - wkcdcnt
ans = (b - a + 1) - candiv

if rem1 > 0:
    ans -= 1

# Output
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import time
import re
import math
import fractions

def main():
    A,B,C,D=map(int,input().split())
    N=B-A+1
    sc=hoge(A,C)-A+1
    if sc<=N:
        ccount=math.floor((N+C-sc)/C)
    else:
       ccount=0

    sd=hoge(A,D)-A+1
    if sd<=N:
        dcount=math.floor((N+D-sd)/D)
    else:
       dcount=0

    CD=C * D / fractions.gcd(C, D)
    scd=hoge(A,CD)-A+1
    if scd<=N:
        cdcount=math.floor((N+CD-scd)/CD)
    else:
       cdcount=0
    print(N-(ccount+dcount-cdcount))


def hoge(a,b):
    return math.ceil(a/b)*b
start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))
#"YNeos"[True::2]
#A=list(map(int,input().split()))
#A,B,C=map(int,input().split())
#n=int(input())
# global n,A,s,memo,mx,mn,L,B

Submission status: Wrong Answer

Solution code:
import math
import fractions

A,B,C,D=map(int,input().split())
A=A-1
G=(fractions.gcd(C,D))
#print(G)

MM=((B//C)+(B//D)-(B//(C*D/G)))
NN=((A//C)+(A//D)-(A//(C*D/G)))
#print(MM,NN)
#print(B-MM)
#print(A-NN)
#print((B-MM)-(A-NN))  
GG=((B-MM)-(A-NN)) 
print(int(GG))

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

ans = B - A + 1

# 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 = int(C * D / fractions.gcd(C,D))

ans += -countX(C) - countX(D) + countX(Z)

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D =  map(int,input().split(" "))
if A == 1:
    NUM = B
    NUM -= int(B / C)
    NUM -= int(B / D)
    NUM += int(B / int((C*D)/fractions.gcd(C,D)))
    print(NUM)
else:  
    NUM = B
    NUM -= int(B / C)
    NUM -= int(B / D)
    NUM += int(B / int((C*D)/fractions.gcd(C,D)))
    #print(NUM)
    LNUM = A-1
    LNUM -= int((A-1) / C)
    LNUM -= int((A-1) / D)
    LNUM += int((A-1) / int((C*D)/fractions.gcd(C,D)))
    #print(LNUM)
    print(NUM - LNUM)

Submission status: Wrong Answer

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

import fractions

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

com = lcm(c,d)

total = b - a + 1
fir = int(b/c) - int((a-1)/c)
sec = int(b/d) - int((a-1)/d)
rem = int(b/com) - int((a-1)/com)

result = total - (fir + sec -rem)
  
print(result)

Submission status: Wrong Answer

Solution code:
import fractions
a, b, c, d = map(int, input().split())
e = int(c*d/fractions.gcd(c, d))
if a%c != 0:
	fc = (int(a/c)+1)*c
else:
	fc = (int(a/c))*c
if b%c != 0:
	tc = (int(b/c))*c
else:
	tc = (int(b/c))*c
sc = int((tc - fc)/c)+1

if a%d != 0:
	fd = (int(a/d)+1)*d
else:
	fd = (int(a/d))*d
if b%d != 0:
	td = (int(b/d))*d
else:
	td = (int(b/d))*d
sd = int((td - fd)/d)+1

if a%e != 0:
	fe = (int(a/e)+1)*e
else:
	fe = (int(a/e))*e
if b%e != 0:
	te = (int(b/e))*e
else:
	te = (int(b/e))*e
se = int((te - fe)/e)+1

ss = (b-a+1)-(sc+sd-se)
print(ss)

Submission status: Wrong Answer

Solution code:
# C
# import math

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

num = B-A+1
if A%C==0:
    x=A
else:
    x = A-A%C+C
if B%C==0:
    y=B
else:
    y = B-B%C
C_multi = (y-x)//C+1
# print(x)
# print(y)
# print(C_multi)

if A%D==0:
    x=A
else:
    x = A-A%D+D
if B%D==0:
    y=B
else:
    y = B-B%D
D_multi = (y-x)//D+1
# print(x)
# print(y)
# print(D_multi)


a=C
b=D
while b:
    a, b = b, a % b
Z = a
E = C * D / Z
if A%E==0:
    x=A
else:
    x = A-A%E+E
if B%E==0:
    y=B
else:
    y = B-B%E
E_multi = (y-x)//E+1

print(int(num-C_multi-D_multi+E_multi))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from math import ceil, floor
A, B, C, D = map(int, input().split())
c_tmp = C
d_tmp = D
c_idx = 2
d_idx = 2
cd = 0
while True:
    if c_tmp == d_tmp:
        cd = c_tmp
        break
    if c_tmp < d_tmp:
        c_tmp = C * c_idx
        c_idx += 1
    elif c_tmp > d_tmp:
        d_tmp = D * d_idx
        d_idx += 1
c_cnt = ceil((B) / C) - (A-1) // C
d_cnt = ceil((B) / D) - (A-1) // D
cd_cnt = ceil((B) / (cd)) - (A-1) // (cd)
# c_cnt = (B+1) // C - (A-1) // C
# d_cnt = (B+1) // D - (A-1) // D
# cd_cnt = B // (cd) - (A-1) // (cd)
minus = c_cnt + d_cnt - cd_cnt
print(B - A - minus + 1)

Submission status: Wrong Answer

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


def gcd(x, y):
    x = abs(x)
    y = abs(y)
    while y:
        x, y = y, x % y
    return x

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

def Ndivingcd(x, y, i):
    Ntoi   = i - (int)(i/x) - (int)(i/y)
    return Ntoi

CDgcd = lcm(C,D)
Ningcd = CDgcd - (int)(CDgcd/C) - (int)(CDgcd/D) +1
Nloop = math.floor(B / CDgcd)-math.floor(A / CDgcd)
firstgcd = math.floor(A / CDgcd)*CDgcd
lastgcd  = math.floor(B / CDgcd)*CDgcd
NdivtoA=0
if not A==firstgcd:
    NdivtoA = Ndivingcd(C,D,A-firstgcd-1)
NdivtoB = Ndivingcd(C,D,B-lastgcd)
N = Nloop*Ningcd+NdivtoB-NdivtoA
print(N)

Submission status: Wrong Answer

Solution code:
import math
import fractions

def main():

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

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

    count_C = (B//C - (A-1)//C)
    print("count_C = ", count_C)

    count_D = (B//D - (A-1)//D)
    print("count_D = ", count_D)

    count_CD = (B//CD - (A-1)//CD)
    print("count_CD = ", count_CD)

    print(int(B-A+1 - (count_C + count_D - count_CD)))

if __name__ == '__main__':
    main()

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=input().split()
a=int(a)
b=int(b)
c=int(c)
d=int(d)

x=a+a%c
y=a+a%d
e=lcm(c,d)
z=a+a%e
x2=(b-x)//c+1
if x>b:
    x=0
y2=(b-y)//d+1
if y>b:
    y=0
z2=(b-z)//e+1
if z>b:
    z=0
if c>b and d>b:
    print(b-a+1)
elif d>b:
    print(b-a+1-x2)
elif c>b:
    print(b-a+1-y2)
elif e>b:
    print(b-a-x2-y2+1)
else:
    print(b-a+1-x2-y2+z2)

Submission status: Wrong Answer

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

wari = (int(b/c) + int(b/d) - int(b/(c*d)) - (int((a-1)/c) + int((a-1)/d) - int((a-1)/(c*d)) ))

print(str(b - a - wari + 1))

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D = map(int, input().split())
if B%C >= B-A:
    x = 0
else:
    x = abs(A-B)//C + 1
if B%D >= B-A:
    y=0
else:
    y = abs(A-B)//D + 1
if B%((C*D)//fractions.gcd(C,D)) >= B-A:
    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:
import fractions
A,B,C,D=map(int,input().split())
X=0
L=0
M=0
N=0
E=C*D/fractions.gcd(C,D)
if A%C==0 or B%C==0:
    L=(B-A)//C+1
else:
    L=(B-A)//C

if A%D==0 or B%D==0:
    M=(B-A)//D+1
else:
    M=(B-A)//D
if B-A>=E:    
    if A%E==0 or B%E==0:
        N=(B-A)//E+1
    else:
        N=(B-A)//E
else:
    if A%E==0 or B%E==0:
        N=(B-A)//E+2
    else:
        N=(B-A)//E+1
X=B-A+1-L-M+N
print(int(X))

Submission status: Wrong Answer

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

d=math.floor(B/D)
dd=math.ceil(A/D)

CD=(C*D)//fractions.gcd(C,D)
cd=math.floor(B/(CD))
cdcd=math.ceil(A/(CD))

print((B-A+1)-((c-cc+1)+(d-dd+1)-(cd-cdcd+1)))

Submission status: Wrong Answer

Solution code:
lis=list(map(int,input().split()))
A=lis[0]
B=lis[1]
C=lis[2]
D=lis[3]
sum=B-A+1
times=C*D
restac=A%C
restbc=B%C
restad=A%D
restbd=B%D
restat=A%times
restbt=B%times
x=int((B-restbc)/C)-int((A-restac)/C)
y=int((B-restbd)/D)-int((A-restad)/D)
z=int((B-restbt)/times)-int((A-restat)/times)
if restac==0:
  x+=1
if restad==0:
  y+=1
if(restat==0):
  z+=1
print(sum-x-y+z)

Submission status: Wrong Answer

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



A,B,C,D = map(int,input().split())
CD = lcm(C, D)
# print("CD:",CD)
# print(" ===C====",math.ceil(A/C),math.floor(B/C))
# print(A/C,B/C)
# print(" ===D====",math.ceil(A/D),math.floor(B/D))
# print(A/D,B/D)
# print(" ===CD====",math.ceil(A/CD),math.floor(B/CD))
# print(A/CD,B/CD)


Cwari = math.floor(B/C) - math.ceil(A/C) +1
# print("Cwari:",Cwari)

Dwari = math.floor(B/D) - math.ceil(A/D)+1
# print("Dwari:",Dwari)

CDwari = math.floor(B/CD) - math.ceil(A/CD)+1
# print("CDwari:",CDwari)


print(B-A+1-(Cwari+Dwari-CDwari))

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)-1
r = (b//c)*c
k1 = (r-l)//c+1
if c==1:
	k1-=1;


l = (ceil(a/d)*d)-1
r = (b//d)*d
k2 = (r-l)//d+1
if d==1:
	k1-=1;

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

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

print(ans)

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=int((BC-AC)/lis[2])+1
ABD=int((BD-AD)/lis[3])+1
ABCD=int((BCD-ACD)/CD)+1
ans=lis[1]-lis[0]+1-(ABC+ABD-ABCD)

print(ans)
#print(AC,AD,BC,BD,ACD,BCD,ABC,ABD,ABCD)

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d=map(int,input().split())
yoso=b-a+1
kobai=fractions.gcd(c,d)
AC=c-(a%c)
if AC==c:
  AC=0
BC=b%c
AD=d-(a%d)
if AD==d:
  AD=0
BD=b%d
Akobai=a%kobai
if Akobai==kobai:
  Akobai=0
Bkobai=b%kobai
C=0
if AC+BC>=(yoso%c):
  C=yoso//c
else:
  C=(yoso//c)+1
D=0
if AD+BD>=(yoso%d):
  D=yoso//d
else:
  D=(yoso//d)+1
CD=0
if Akobai+Bkobai>=(yoso%kobai):
  CD=yoso//kobai
else:
  CD=(yoso//kobai)+1
print(yoso+CD-C-D)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import math
a,b,c,d = map(int,input().split())
 
an1 = math.floor(b/c)
an2 = math.floor((a-1)/c)
an3 = math.floor(b/d)
an4 = math.floor((a-1)/d)
 
gcd = round(c * d / gcd(c, d))
 
an5 = math.floor(b/gcd)
an6 = math.floor((a-1)/gcd)
an = an1-an2 + an3-an4 -(an5-an6)
print((b-a+1)-an)

Submission status: Wrong Answer

Solution code:
import fractions

A, B, C, D = map(int, input().split())
tmp = fractions.gcd(C, D)
lcd = int((C * D) / tmp)
acnt1 = int((A - 1) / C)
acnt2 = int((A - 1) / D)
acnt3 = int(B / C)
acnt4 = int(B / D)
acnt5 = int((A - 1) / lcd)
acnt6 = int(B / lcd)
ans = B
atmp = acnt3 + acnt4 - acnt5 - acnt6 - acnt1 - acnt2
ans -= atmp
ans = ans - A + 1
print(ans)

Submission status: Wrong Answer

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

A =A-1
CD = C * D / gcd(C, D)
num_A_C = int(A / C)
num_A_D = int(A / D)
num_A_CD = int(A / CD)
num_B_C = int(B / C)
num_B_D = int(B / D)
num_B_CD = int(B / CD)

num_C =num_B_C - num_A_C
num_D =num_B_D - num_A_D
num_CD =num_B_CD - num_A_CD

ans = B - A -num_C - num_D + num_CD
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

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

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

Conly = 1 + ( ( B - (B%C) ) - ( A + C - (A%C) ) )//C
Donly = 1 + ( ( B - (B%D) ) - ( A + C - (A%D) ) )//D
CandD = 1 + ( ( B - (B%G) ) - ( A + C - (A%G) ) )//G

result = B - A +1 - ( Conly + Donly - CandD )

print(result)

Submission status: Wrong Answer

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

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

C_comp = int((B-(B%C))/C) - int(((A-1)-(A-1)%C)/C)
D_comp = int((B-(B%D))/D) - int(((A-1)-(A-1)%D)/D)
CD_comp = int((B-(B%lcm(C,D)))/lcm(C,D)) - int(((A-1)-(A-1)%lcm(C,D))/lcm(C,D))

print((B - A + 1) - (C_comp + D_comp - CD_comp))

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int,input().split())
C_min = 0
D_min = 0
CD_min = 0
for i in range(A,B+1):
  if i % C == 0:
    C_min = i
  if i % D == 0:
    D_min = i
  if i % C == 0 and i % D == 0:
    CD_min = i
  if C_min > 0 and D_min > 0 and CD_min > 0:
    break
C_cou = 0
D_cou = 0
CD_cou = 0
if C_min > 0:
	C_cou = (B - C_min) // C + 1
if D_min > 0:
	D_cou = (B - D_min) // D + 1
if CD_min > 0:
	CD_cou = (B - CD_min) // (C*D) + 1
ans = B - A - C_cou - D_cou + CD_cou + 1
print(ans)

Submission status: Wrong Answer

Solution code:
def u(a,b):
  if b == 0:
    return a
  return u(b, a%b)

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

e=int(c*d/u(c,d))
a=a-1
ac = int(a / c)
bc = int(b / c)
ad = int(a / d)
bd = int(b / d)
ae = int(a / e)
be = int(b / e)

print(b - a - (bc - ac + bd - ad ) + (be - ae))

Submission status: Wrong Answer

Solution code:
# 3.4.3 ONLY!!!
import fractions
import math


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-(b//c-math.ceil(a/c))-(b//d - math.ceil(a/d))+(b//cd-math.ceil(a/cd)))

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D = map(int, input().split())
if B%C > B-A:
    x = 0
else:
    x = abs(A-B)//C + 1
if B%D > B-A:
    y=0
else:
    y = abs(A-B)//D + 1
if B%((C*D)//fractions.gcd(C,D)) > B-A:
    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:
A, B, C, D = map(int, input().split())
count = 0
countC = 0
countD = 0

countC = round((B- A +1) / C)
countD = round((B- A +1) / D)
print(B-A+2 - countC - countD)

Submission status: Wrong Answer

Solution code:
# 2019/06/22
# AtCoder Beginner Contest 131 - C

import fractions
# Least Common Multiple
def lcm_fgf(a, b):
    return int(a * b / fractions.gcd(a, b))

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

clist = list()
dlist = list()
cdlist = list()

cd = lcm_fgf(c, d)

# wkc = (a // c) * c
# wkd = (a // d) * d
# wkcd = (a // cd) * cd

wkccnt = (b - a + 1) // c
wkdcnt = (b - a + 1) // d
wkcdcnt = (b - a + 1) // cd
rem1 = (b - a + 1) % c
rem2 = (b - a + 1) % d

candiv = wkccnt + wkdcnt - wkcdcnt
ans = (b - a + 1) - candiv

if rem1 + rem2 > 0:
    ans -= 1

# Output
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import fractions

input=stdin.readline().rstrip().split()
A=int(input[0])
B=int(input[1])
C=int(input[2])
D=int(input[3])

output=0
Cmax=int((B)/C)
Cmin=int(A/C)
Dmax=int((B)/D)
Dmin=int(A/D)
CD=C*D/fractions.gcd(C,D)
CDmax=int((B)/CD)
CDmin=int(A/CD)
output=(B-A+1)-((Cmax-Cmin)+(Dmax-Dmin)-(CDmax-CDmin))
print(output)

Submission status: Wrong Answer

Solution code:
s, n, c, d = map(int, input().split())
cnt = n - s + 1
for i in [c, d]:
    m = s
    while m % i:
        m += 1
    for j in range(m, n + 1, i):
        if j % c == 0 and j % d == 0 and i == d:
            continue
        cnt -= 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
import fractions
 
A , B , C , D = map(int,input().split())
 
 
ans = 0
 
 
# 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 = int(C * D // fractions.gcd(C,D))
 
ans += B - A + 1 - countX(C) - countX(D) + countX(Z) + 1
 
print(ans)

Submission status: Wrong Answer

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

def getAns(a, b, c):
  if a % c == 0:
    start = a
  else:
    start = a + c - (a % c)
    if start > b:
      return 0
    
  if b % c == 0:
    end = b
  else:
    end = b - c + (b % c)
    if end < a:
      return 0
    
  num_c = max((end - start) // c + 1, 0)
  return num_c

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

# cについて
num_c =getAns(a,b,c)
#print(num_c)

# dについて
num_d =getAns(a,b,d)
#print(num_d)

# cとdの公倍数について
cd = c * d // gcd(c,d)
num_cd = getAns(a,b,cd)
#print(num_cd)

print(b - a + 1 - (num_c + num_d - num_cd))

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d = map(int,input().split())
cnt = 0
numc = b // c - (a - 1) // c
numd = b // d - (a - 1) // d
com = c * d / fractions.gcd(c,d)
numcd = b // com - (a - 1) // com
print(int(b - a + 1 - (numc + numd - numcd)))
# minc = a // c 
# if int(a % c) != 0:
#         minc += 1
# mind = a // d
# if int(a % d) != 0:
#         mind += 1
# cmul = (b - minc * c) // c + 1
# dmul = (b - mind * d) // d + 1
# com = c * d / fractions.gcd(c,d)
# mincd = a // com
# if int(a % com) != 0:
#         mincd += 1
# cdmul = (b - mincd * com) // com + 1
# print(int(b - a + 1 - (cmul + dmul - cdmul)))

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())
E=lcm(C,D)
for i in range(A,A+C):
	if i%C==0:
		p=i
q=int((B-p)/C)
for j in range(A,A+D):
	if j%D==0:
		r=j
s=int((B-r)/D)
for k in range(A,A+E):
	if k%E==0:
		t=k
k=int((B-t)/E)
print((B-A+1)-(q+s-k+1))

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int, input().split())
x=0
for i in range(a,b):
  if(i%c!=0 and i%d!=0):
    x+=1
print(x)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d=map(int,input().split())
ans=b-a+1
minac=c*(-(-a//c))
minad=d*(-(-a//d))
maxbc=c*(b//c)
maxbd=d*(b//d)
cn=(maxbc-minac)//c+1
dn=(maxbd-minad)//d+1
cd=c*d//gcd(c,d)
cdn=(-(-((max(maxbc,maxbd)-min(minac,minad)))//(cd)))
ans-=(cn+dn-cdn)
print(ans)

Submission status: Wrong Answer

Solution code:
#C
from math import ceil, floor
from fractions import gcd
A,B,C,D = map(int, input().split())
X = C * D / gcd(C, D)

def retLR(A, B, num):
    #return A <= l*num < r*num <= B, length
    l = ceil(A/num)
    r = floor(B/num)
    if r*num < A and B < l*num :
        length = 0
    elif r*num < A or B < l*num : 
        length = 1
    else:
        length = r - l + 1
    return length

a1 = retLR(A,B,C)
a2 = retLR(A,B,D)
a3 = retLR(A,B,X)

if C == D:
    subst = a1
else:
    subst = a1 + a2 - a3
if A == B:
    if A == C or A == D: ans = 0
    else: ans = 1
else:
    ans = (B - A + 1) - subst
print(ans)

Submission status: Wrong Answer

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

def lcm(c,d):
    return c*d//gcd(c,d)

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

l = lcm(c,d)
res = 0
bal = b-a
print(bal - ( bal//c + bal//d - bal//l ))

Submission status: Wrong Answer

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

def yes(a,b):
    if a%b==0:
        return int(a/b)-1
    else :
        return int(a/b)

A,B,C,D=map(int,input().split())
count=0
C_count=int(B/C)-yes(A,C)
D_count=int(B/D)-yes(A,D)
CD_count=int(B/C/D*gcd(C,D))-yes(A,C*D/gcd(C,D))
count = B - A + 1 - (C_count + D_count - CD_count)
print("{}".format(count))

Submission status: Wrong Answer

Solution code:
import math
import fractions
 
A , B , C , D = map(int,input().split())
 
 
ans = 0
 
 
# 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 = int(C * D // fractions.gcd(C,D))
 
ans += B - A + 1 - countX(C) - countX(D) + countX(Z) - 1
 
print(ans)

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
B = a[0]
A = a[1]
C = a[2]
D = a[3]
ANS_1 = A - A//C - A//D +  A//(C*D)
E = B-1
ANS_2 = E - E//C - E//D +  E//(C*D)
if E  > 0:
    print(ANS_1 - ANS_2)
elif C == D:
    print(A - A//C - (E - E//C))
else:
    print(ANS_1)

Submission status: Wrong Answer

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

a,b,c,d=(int(x) for x in input().split())
bs=int(lcm(c,d))
kihon=int(bs)+1-int(bs/c)-int(bs/d)
if a%bs==0:
    saisyo=int(a)
else:
    saisyo=((int(a)//int(bs))+1)*int(bs)
saidai=(int(b)//int(bs))*int(bs)
count=int(kihon)*int((int(saidai)-int(saisyo))/int(bs))
fro=int(saisyo)-int(a)
bac=int(b)-int(saidai)
ans=int(fro)-((int(fro)//int(c))+(int(fro)//int(d)))+int(bac)-((int(bac)//int(c))+(int(bac)//int(d)))
print(math.floor(int(ans)+int(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 = map(int,input().split())
m = int(c*d/gcd(c,d))
if c == 1 or d == 1:
  print(0)
  exit()
if a%c < b%c and a%c == 0:
  xc = (b-a+1)//c + 1
elif a%c < b%c:
  xc = (b-a+1)//c
elif a%c > b%c and b%c == 0 and a%c == 1:
  xc = (b-a+1)//c
elif a%c > b%c:
  xc = (b-a+1)//c +1
elif a%c == b%c and a%c == 0:
  xc = (b-a+1)//c +1
else:
  xc  = (b-a+1)//c

if a%d < b%d and a%d == 0:
  xd = (b-a+1)//d +1
elif a%d < b%d:
  xd = (b-a+1)//d
elif a%d > b%d and b%d == 0 and a%d == 1:
  xd = (b-a+1)//d
elif a%d > b%d:
  xd = (b-a+1)//d +1
elif a%d == b%d and a%d == 0:
  xd = (b-a+1)//d +1
else:
  xd  = (b-a+1)//d

if a%m < b%m and a%m == 0:
  xm = (b-a+1)//m +1
elif a%m < b%m:
  xm = (b-a+1)//m
elif a%m > b%m and b%m == 0 and a%m == 1:
  xm = (b-a+1)//m
elif a%m > b%m:
  xm = (b-a+1)//m +1
elif a%m == b%m and a%m == 0:
  xm = (b-a+1)//m +1
else:
  xm  = (b-a+1)//m

print(b-a+1-xc-xd+xm)

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int, input().split())
if B<C:
    if B<D:
        print(B-A+1)
    else:
        ist=1
        ien=1
        while D*ist<A:
            ist=ist+1
        while D*(ien+1)<B:
            ien=ien+1
        print(B-A+1-ien+ist-1)
elif B<D:
    ist=1
    ien=1
    while C*ist<A:
        ist=ist+1
    while C*(ien+1)<B:
        ien=ien+1
    print(B-A+1-ien+ist-1)
else:
    ist,ien,jst,jen,kst,ken=1,1,1,1,1,0
    while C*ist<A:
        ist=ist+1
    while D*jst<A:
        jst=jst+1
    while C*(ien+1)<B:
        ien=ien+1
    while D*(jen+1)<B:
        jen=jen+1
    if C%D!=0 and D%C!=0:
        while C*D*kst<B:
            kst=kst+1
        while C*D*(ken+1)<B:
            ken=ken+1
    print(B-A+1-ien+ist-1-jen+jst-1+ken-kst+1)

Submission status: Wrong Answer

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


#[1,x]のうちCで割り切れる
def C(x):
    return x // c


#Dで割り切れる
def D(x):
    return x // d


#C*Dで割り切れる
def CD(x):
    return x // (c * d)


#CまたはDで割り切れる
def CorD(x):
    return C(x) + D(x) - CD(x)


#CでもDでも割り切れない
def CnorD(x):
    return x - CorD(x)


print(CnorD(b) - CnorD(a - 1))

Submission status: Wrong Answer

Solution code:
import math
import fractions
 
A , B , C , D = map(int,input().split())
 
 
ans = 0
 
 
# 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 = int(C * D // fractions.gcd(C,D))
 
ans += B - A + 1 - countX(C) - countX(D) + countX(Z)
 
print(ans)

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)

def num_of_mod0(mod):
    if A%mod == 0:
        start = A
    else:
        start = (A//mod +1) * mod

    end = (B // mod) * mod

    return (end - start) / mod +1

ans =(B-A+1)-(num_of_mod0(C) + num_of_mod0(D)- num_of_mod0(lcm(C,D)))
ans = int(ans)
print(ans)

Submission status: Wrong Answer

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

#a,bの最大公約数
def gcd(C, D):
    while D:
        C, D = D, C % D
    return C

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


CD = lcm(C, D)

cntC = int(B / C) - int(A / C)
cntD = int(B / D) - int(A / D)
cntCD = int(B / CD) - int(A / CD)

# print(cntC, cntD, cntCD, CD)
calc = (B-A+1) - (cntC + cntD - cntCD)

print(calc)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int,input().split())
C_min = 0
D_min = 0
CD_min = 0
for i in range(A,B+1):
  if i % C == 0:
    C_min = i
  if i % D == 0:
    D_min = i
  if i % C == 0 and i % D == 0:
    CD_min = i
  if C_min > 0 and D_min > 0 and CD_min > 0:
    break
C_cou = 0
D_cou = 0
CD_cou = 0
if C_min > 0:
	C_cou = (B - C_min) // C
if D_min > 0:
	D_cou = (B - D_min) // D
if CD_min > 0:
	CD_cou = (B - CD_min) // (C*D)
ans = B - A - C_cou - D_cou + CD_cou + 1
print(ans)

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

#lst = [i for i in range(a, b + 1)]

n = abs((b // c) - ((a - 1) // c))
m = abs((b // d) - ((a - 1) // d))
cd = c * d
l = abs((b // cd) - ((a - 1) // cd))

g_cd = gcd(c, d)
if g_cd != 1:
    l = l + 1


nml = n + m - l

#print(n, m, l, nml)

print((b - a + 1) - nml)

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)


def abc():
    from math import ceil
    a, b, c, d = map(int, input().split())

    cnt_all = b - a + 1

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

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

    cd = lcm(c, d)
    l = ceil(a / cd)
    r = b // cd
    cnt_cd = r - l + 1

    print(cnt_all - (cnt_c + cnt_d - cnt_cd))


abc()

Submission status: Wrong Answer

Solution code:
import math
import fractions

A,B,C,D=map(int,input().split())
A=A-1
G=int(fractions.gcd(C,D))
#print(G)

MM=int((B//C)+(B//D)-(B//(C*D/G)))
NN=int((A//C)+(A//D)-(A//(C*D/G)))
#print(MM,NN)
#print(B-MM)
#print(A-NN)
print((B-MM)-(A-NN))

Submission status: Wrong Answer

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

E = 0
num = A
F = 0
if C > D:
    E = C
    F = D
else:
    E = D
    F = C

ans = 0
while num <= B:
    counter = 0
    for n in range(num, num + E):
        if n > B:
            break

        if n % C == 0:
            counter+=1
        elif n % D == 0:
            counter+=1

        if counter == 2:
            break

    num = num + E
    ans += counter

print(B-A-ans+1)

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) -int((a-1)//c)
canD = int(b//d) - int((a-1)//d)
dbCD = int(b//lcm(c,d)) -int((a-1)//lcm(c,d))
print((b-a+1) -canC - canD + dbCD-1)