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 sys
sys.setrecursionlimit(10**7)
import itertools


debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

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

    import math
    ac = math.ceil(a/c)
    bc = math.floor(b/c)
    nc = bc - ac + 1

    ad = math.ceil(a / d)
    bd = math.floor(b / d)
    nd = bd - ad + 1

    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):
        #import fractions
        #return (x * y) // fractions.gcd(x, y)
        return (x * y) // gcd(x, y)

    cd = lcm(c, d)
    acd = math.ceil(a / cd)
    bcd = math.floor(b / cd)
    ncd = bcd - acd + 1

    total = b - a + 1
    dprint(total, nd, nc, ncd)
    print(total - nd - nc + ncd)

solve()

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 = 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:
import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

# A以上B以下にXの倍数が幾つあるか？ 1 < A < B
def check(A, B, X):
    x = int((A-1) / X)
    y = int((B-0) / X)
    return y - x

import fractions

def main():
    A, B, C, D = i2nn()
    # A以上B以下の数
    n = B - A + 1
    # Cの倍数
    n -= check(A, B, C)
    # Dの倍数
    n -= check(A, B, D)
    # GCD(C, D)の倍数
    E = C * D // fractions.gcd(C, D)
    n += check(A, B, E)
    print(n)

main()

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

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:
a,b,c,d=map(int,input().split())
ans=(b-a+1)-(b//c-a//c)-(b//d-a//d)+(b//(c*d)-a//(c*d))
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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


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


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


n1 = B//C-ceil(A/C)+1
n2 = B//D-ceil(A/D)+1
n3 = B//(lcm(C, D))-ceil(A/lcm(C, D))+1
allNum = B-A+1
print(allNum-n1-n2+n3)

Submission status: Wrong Answer

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

sumC=0
div = -(A%C)+C
if A+div <= B:
  first = A+div
  sumC = Decimal(B-first)//Decimal(C) + 1
  
sumD=0
div = -(A%D)+D
if A+div <= B:
  first = A+div
  sumD = Decimal(B-first)//Decimal(D) + 1
  
sumCD=0
f=fractions.gcd(C,D)
f2=C*D//f
div = -(A%f2)+f2
if A+div <= B:
  first = A+div
  sumCD = Decimal((B-first))//Decimal(f2) + 1
  
print(B-A+1-(sumC+sumD-sumCD))

Submission status: Wrong Answer

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


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


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

c = B // C - A // C
d = B // D - A // D
cd = B // lcm(C, D) - A // lcm(C, D)

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from math import ceil
lcm = lambda x, y: x * y // gcd(x, y)
def solve():
    a, b, c, d = map(int, input().split())
    C = len(range(ceil(a / c) * c, b + 1, c))
    D = len(range(ceil(a / d) * d, b + 1, d))
    cd = lcm(c, d)
    CD = len(range(ceil(a / cd) * cd, b + 1, cd))
    print(b - a + 1 - (C + D - CD))
solve()

Submission status: Wrong Answer

Solution code:

def gcd(a,b):
  x = max([a,b])
  y = min([a,b])
  while y:
    x, y = y, x % y
  return x

# x * y = lcm(x, y) // gcd(x, y)より
def lcm(x, y):
  return x * y // gcd(x, y)


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

cd = lcm(c,d)
b_c = b // c
b_d = b // d
a_c = (a-1)//c
a_d = (a-1)//d
b_cd = b//(cd)
a_cd = a//(cd)
nums = b-a+1

ans = nums - (b_c - a_c) - (b_d - a_d) + (b_cd - a_cd)
print(ans)
#print(nums , b-c , a_c , b-d , a_d , b_cd , a_cd)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from collections import defaultdict
import math
import re

def not_divided(x, A, B):
    if x > B:
        return 0
    lower = math.ceil(A / x)
    upper = math.floor(B / x)
    num = upper - lower + 1
    return num

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

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

    # not divided by C
    C_num = not_divided(C, A, B) 
    D_num = not_divided(D, A, B) 

    CD = C * D // gcd(C, D)
    CD_num = not_divided(CD, A, B)

    C_or_D_num = C_num + D_num - CD_num

    num = (B - A + 1) - C_or_D_num

    print(num)


if __name__ == '__main__':
    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

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

tgC = int(B/C) - int((A-1)/C)
tgD = int(B/D) - int((A-1)/D)
tgCD = int(B/CD) - int((A-1)/CD)


print((B-A+1)-(tgC+tgD-tgCD))

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    
    

cd = C*D

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

print(k + scd -sc -sd)

Submission status: Wrong Answer

Solution code:
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 = 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:
a,b,c,d = map(int, input().split())
coun=0
for i in range(a,b):
    if i%c!=0 and i%d!=0:
      coun+=1
print(coun)

Submission status: Wrong Answer

Solution code:
import fractions

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

count = 0
i = A
d = B - A

ta = d // C
tb = d // D
tc = d//(C * D // fractions.gcd(C, D))

print(d-(ta+tb-tc))

Submission status: Wrong Answer

Solution code:
A,B,C,D = list(map(int, input().split()))
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
l=C*D//gcd(C,D)
print(B+1-A -B//C+(A-1)//C -B//D+(A-1)//D +B//l+(A-1)//l )

Submission status: Wrong Answer

Solution code:
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 = 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

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

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
t = b//c-a//c
u = b//d-a//d
if a%c == 0:
  t += 1
if a%d == 0:
  u += 1
def gcd(p,q):
    if p%q != 0:
        return gcd(q,p%q)
    else:
        return q
k = c*d//gcd(c,d)
v = b//k-a//k
if a != b:
  print(b-a+1-t-u+v)
else:
  if a%c == 0 and a%d == 0:
    print(0)
  else:
    print(1)

Submission status: Wrong Answer

Solution code:
def main():
    A, B, C, D = [int(n) for n in input().split()]
    min_c = A // C if A % C == 0 else (A // C)+1
    max_c = B // C if B % C == 0 else (B // C)-1
    min_d = A // D if A % D == 0 else (A // D)+1
    max_d = B // D if B % D == 0 else (B // D)-1
    min_pro = A // (C*D) if A % (C*D) == 0 else (A // (C*D))+1
    max_pro = B // (C*D) if B % (C*D) == 0 else (B // (C*D))-1

    print((B-A+1) - (max_c-min_c+1) - (max_d-min_d+1) + (max_pro-min_pro + 1))
main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

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

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

def get_b_cnt(a,b,x):
    res = 0
    N = b - a + 1
    x1 = a % x 

    if x1 < N:
        res += 1

    N2 = N - x1 -1

    if N2 > 0:
        res += (N2 // x)

    return res


def solve(A: int, B: int, C: int, D: int):
    E = lcm(C,D)

    print(B-A+1-(get_b_cnt(A,B,C)+get_b_cnt(A,B,D)-get_b_cnt(A,B,E)))

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)

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())
cd = lcm(a,b)
ans = 0
ans += (b // c) - (a // c)
ans += (b // d) - (a // d)
ans -= (b // cd) - (a // cd)
ans = (b - a + 1) - ans

print(ans)

Submission status: Wrong Answer

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

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 = lcm(c, d)
c_num = int(b/c) - int((a-1)/c)
d_num = int(b/d) - int((a-1)/d)
l_num = int(b/l) - int((a-1)/l)

print((b - a + 1) - c_num - d_num + l_num)

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())
B += 1

X1 = A - ((A // C) + (A // D) - (A // lcm(C, D)))
X2 = B - ((B // C) + (B // D) - (B // lcm(C, D)))
print(X2 - X1)

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)

e=lcm(c,d)


def k(a,b):
    return a//b


if c==1 or d==1:
    print(0)
elif c==d:
    ans_h=k(b,c)-k(a-1,c)
    print(b-a+1-ans_h)
else:
    ans_h=k(b,c)+k(b,d)-k(b,e)-k(a-1,c)-k(a-1,d)
    print(b-a+1-ans_h)

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())
div = lcm(c,d)

x_div = a//div
y_div = b//div
x_c = a//c
y_c = b//c
x_d = a//d
y_d = b//d
print(b-a+1+(y_div-x_div)-(y_c-x_c)-(y_d-x_d))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d = map(int,input().split())
ans = b - a + 1#ok
a -= 1#ok

g = gcd(c,d)
n = c / g
m = d / g
temp = n*m*g

ans -= -int(a/c) + int(b/c)
ans -= -int(a/d) + int(b/d)
ans += -int(a/temp) + int(b / temp)

print(int(ans))

Submission status: Wrong Answer

Solution code:
from math import ceil
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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


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


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


n1 = B//C-ceil(A/C)+1
n2 = B//D-ceil(A/D)+1
n3 = B//(lcm(C, D))-ceil(A/lcm(C, D))+1
allNum = B-A+1
print(allNum-n1-n2+n3)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

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

count_c = (b - a) // c
count_d = (b - a) // d
count_g = (b - a) // g
s = b - a - count_c - count_d + count_g

print(s)

Submission status: Wrong Answer

Solution code:
import math
# 最大公約数


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


a, b, c, d = map(int, input().split())  # 複数数値入力

# cとdの最小公倍数
lcm = c * d / gcd(c, d)
# print(lcm)
# print(b - a + 1)
# print(int(b / c) - int((a - 1) / c))
# print(int(b / d) - int((a - 1) / d))
# print(int(b/lcm)-int((a-1)/lcm))
print(b - a + 1 - math.floor(b / c) - math.floor(b/d) +
      math.floor((a-1) / c) + math.floor((a-1)/d) + (math.floor(b/lcm)-math.floor((a-1)/lcm)))

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
t = b//c-a//c
u = b//d-a//d
if a%c == 0:
  t += 1
if a%d == 0:
  u += 1
def gcd(p,q):
    if p%q != 0:
        return gcd(q,p%q)
    else:
        return q
k = c*d//gcd(c,d)
v = b//k-a//k
if a != b:
  print(b-a+1-t-u+v)
else:
  if a%c == 0:
    print(0)
  elif a%d == 0:
    print(0)
  else:
    print(1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
a,b,c,d = map(int,input().split())
fc=0
fd=0
tc=0
td=0
i=0
while fc==0 or fd==0:
    i+=1
    if c*i>=a and fc==0:
        fc=1
        tc=c*i
        
    if d*i>=a and fd==0:
        fd=1
        td=d*i
ans=0
ans= (b-a)-((b-tc)//c+(b-td)//d)

print(ans)

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 =  list(map(int,input().split(" ")))
CD = lcm(C,D)

divisibleC = B // C - A//C
divisibleD = B // D - A // D
divisibleCD = B//CD - A//CD 
print(B - A + 1 -divisibleC - divisibleD + divisibleCD )

Submission status: Wrong Answer

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

C_count = (B - 1) // C - A // C
D_count = (B - 1) // D - A // D
CD = C * D
CD_count = (B - 1) // CD - A // CD

print(B - A + 1 + CD_count - C_count - D_count)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify, heapreplace
from collections import defaultdict
from bisect import bisect_left
from math import floor, ceil

def gcd(x, y):
    if x < y:
        x, y = y, x

    if y == 0:
        return x
    else:
        return gcd(y, x%y)

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

class Solution:
    def main(self):
        A, B, C, D = map(int, input().split())
        gcd = lcm(C, D)
        c_and_d =  floor(B/(gcd)) - ceil(A/(gcd)) + 1
        only_c = floor(B/(C)) - ceil(A/(C)) + 1
        only_d = floor(B/(D)) - ceil(A/(D)) + 1
        # print(c_and_d, only_c, only_d)
        res = (B - A + 1) - (only_c + only_d - c_and_d)
        print(res)

if __name__ == '__main__':
    Solution().main()

Submission status: Wrong Answer

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

def lcd(a,b):
    return (a*b)/fractions.gcd(a,b)

import fractions

two = B // C
three = B //D

g = int(lcd(C,D))
print(g)
six = B // (g)

btwo = (A-1) // C
bthree = (A-1) //D
bsix = (A-1) // (g)

a = B - two - three  + six
b = (A-1) - btwo - bthree  + bsix



print(a - b)

Submission status: Wrong Answer

Solution code:
from sys import stdin
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)

def xxx(x,c,d):
    return x - int(x/c) - int(x/d) + int(x/lcm(c,d))

a, b, c, d = [int(x) for x in stdin.readline().rstrip().split()]

ans = 0

aa = xxx(a-1,c,d)
bb = xxx(b,c,d)
ans = bb - aa
print(ans)

Submission status: Wrong Answer

Solution code:
def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A


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


if __name__ == '__main__':
    A, B, C, D = InputToInt()
    ALL = B-A+1
    Cdiv = int(B/C) - int((A-1)/C)
    Ddiv = int(B/D) - int((A-1)/D)
    lcm = C*D/gcd(C, D)
    LCMdiv = int(B/lcm) - int((A-1)/lcm)
    print(ALL-Cdiv-Ddiv+LCMdiv)

Submission status: Wrong Answer

Solution code:
import fractions

def get_num(N, num1, num2):
    lcm = num1 * num2 / fractions.gcd(num1, num2)
    return N - N // num1 - N // num2 + N // lcm


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

print(get_num(B, C, D) - get_num(A - 1, C, D))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

sumC=0
div = -(A%C)+C
if A+div <= B:
  first = A+div
  sumC = (B-first)//C + 1
  
sumD=0
div = -(A%D)+D
if A+div <= B:
  first = A+div
  sumD = (B-first)//D + 1
  
sumCD=0
f=fractions.gcd(C,D)
f2=C*D//f
div = -(A%f2)+f2
if A+div <= B:
  first = A+div
  sumCD = (B-first)//f2 + 1
  
print(B-A+1-(sumC+sumD-sumCD))

Submission status: Wrong Answer

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

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

cd = (c * d) // gcd(c, d)
a_c = (a-1) // c
b_c = b // c
a_d = (a-1) // d
b_d = b // d
a_cd = (a-1) // cd
b_cd = b // cd

print(b - a + 1 - (b_c - a_c) - (b_d - a_c) + (b_cd - a_cd))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

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

c = (B // C) - ((A - 1) // C)
d = (B // D) - ((A - 1) // D)
cd = (B // (lcm(C, D))) - (A - 1) // (lcm(C, D))

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

print(N - c - d + cd)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
x=b-a+1
i=x//c
j=x//d
k=x//(c*d)
if d%c==0 or c%d==0:
  print(x-max(i,j))
else:
  print(x-i-j+k)

Submission status: Wrong Answer

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

minc = math.ceil(a / c)
maxc = math.floor(b / c)
mind = math.ceil(a / d)
maxd = math.floor(b / d)

cd = c * d / fractions.gcd(c, d)
mincd = math.ceil(a / cd)
maxcd = math.floor(b / cd)

x = maxc - minc + 1
y = maxd - mind + 1
z = maxcd - mincd + 1

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

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


def divisible_count(a, b, d):
    return int(math.floor(b / d)) - int(math.floor((a - 1) / d))


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

x = divisible_count(A, B, C)
y = divisible_count(A, B, D)
z = divisible_count(A, B, lcm(C, D))

print(B - A + 1 - (x + y - z))

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

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

E = lcm(C, D)

# B以下
ans_b_c = (B // C) + (B // D) - (B // E)
ans_b = B - ans_b_c
# A未満
ans_a_c = ((A - 1) // C) + ((A - 1) // D) + ((A - 1) // E)
ans_a = (A - 1) - ans_a_c

ans = ans_b - ans_a
print(ans)

Submission status: Wrong Answer

Solution code:
def euclid(a,b):
	c=0
	if (a-b)<0:
		c=a
		a=b
		b=c
	r=-1
	while r!=0:
		r=a%b
		a=b
		b=r
	return a

A,B,C,D=map(int,input().split())
c1=A//C
d1=A//D
c2=B//C
d2=B//D
k=euclid(C,D)
CD=C*D//k
cd1=A//CD
cd2=B//CD
c3=c2-c1
d3=d2-d1
cd3=cd2-cd1
print(B-A+1-c3-d3+cd3)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

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

    import math
    ac = math.ceil(a/c)
    bc = math.floor(b/c)
    nc = bc - ac + 1

    ad = math.ceil(a / d)
    bd = math.floor(b / d)
    nd = bd - ad + 1

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

    cd = lcm(c, d)
    acd = math.ceil(a / cd)
    bcd = math.floor(b / cd)
    ncd = bcd - acd + 1

    total = b - a + 1
    dprint(total, nd, nc, ncd)
    print(total - nd - nc + ncd)

solve()

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

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

count_c = (b - a) // c
count_d = (b - a) // d
s = b - a - count_c - count_d
g = lcm(c, d)
beta = a // g

alpha = (b - a + beta) // g

print(s + alpha)

Submission status: Wrong Answer

Solution code:
import fractions
def lcm(a, b):
    return a * b // fractions.gcd(a, b)
A,B,C,D = map(int,input().split())
E = lcm(C,D)
i = A//C
j = B//C
k = A//D
l = B//D

m = A//E
n = B//E

ans = B - A + 1 - ((j-i) + (l-k) - (n-m))
if (A % C == 0 or A % D == 0 ) and (B % C == 0 or B % D == 0):
    ans -= 1
print(ans)

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())  # 複数数値入力

# cとdの最小公倍数
lcm = c * d / gcd(c, d)
# print(lcm)
# print(b - a + 1)
# print(int(b / c) - int((a - 1) / c))
# print(int(b / d) - int((a - 1) / d))
# print(int(b/lcm)-int((a-1)/lcm))
print(b - a + 1 - int(b / c) - int(b/d) +
      int((a-1) / c) + int((a-1)/d) + (int(b/lcm)-int((a-1)/lcm)))

Submission status: Wrong Answer

Solution code:
from math import ceil
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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)


n1 = max(B//C-ceil(A/C)+1, 0)
n2 = max(B//D-ceil(A/D)+1, 0)
n3 = max(B//(lcm(C, D))-ceil(A/lcm(C, D))+1, 0)
print(B-A+1-n1-n2+n3)

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())
c = B//C-(A-1)//C
d = B//D-(A-1)//D
LCM = lcm(C,D)
l = B//LCM-A//LCM
if C==D==1:
    print(0)
else:
    print(B-A+1-c-d+l)

Submission status: Wrong Answer

Solution code:
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("Bad")
    elif q == 0:print("Good")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

#n = ip()                                     #入力整数1つ
a,b,c,d= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(m)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#a.pop(0)は10^5あるときTLEしやすい!注意!抜くなら逆ソート!
if a == b:
    if a%c and a%d:
        print(1)
    else:print(0)
elif min(a,b)+1 == max(a,b):
    s =0
    if a%c and a%d:s+=1
    if b%c and b%d:s+=1
    print(s)
else:
    sub1 = (b+1)//d - a//d
    sub2 = (b+1)//c - a//c
    inter = lcm(c,d)
    sub3 = (b+1)//inter - a//inter
    print(b-a-sub1-sub2+sub3+1)

Submission status: Wrong Answer

Solution code:
import sys
# input = sys.stdin.readline

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

def div(a, b):
    return a // b

ans = 0
ans += div(B, C)
ans -= div(A - 1, C)
# print("#", ans)
ans += div(B, D)
ans -= div(A - 1, D)
# print("#", ans)
#
ans -= div(B, C * D)
ans += div(A - 1, C * D)
# print("#", ans)

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

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
t = b//c-a//c
u = b//d-a//d
if a%c == 0:
  t += 1
if a%d == 0:
  u += 1
def gcd(p,q):
    if p%q != 0:
        return gcd(q,p%q)
    else:
        return q
k = c*d//gcd(c,d)
v = b//k-a//k
print(b-a+1-t-u+v)

Submission status: Wrong Answer

Solution code:
A, B, C, D = list(map(int, input().split()))
a1 = (A-1)//C
a2 = (A-1)//D
a3 = (A-1)//(C*D)
a = (A-1)-(a1+a2-a3)
b1 = B//C
b2 = B//D
b3 = B//(C*D)
b = B-(b1+b2-b3)
print(b-a)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
# A//C
ac = A // C # 4
bc = B // C # 2
ad = A // D # 3
bd = B // D # 1


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

cd = C * D // gcd(C,D)
acd = A // cd
bcd = B // cd

res = B - A + 1 - bc + ac - bd + ad + bcd - acd
 

if B % C == 0:
    res -= 1
if B % D == 0:
    res -= 1
if B % cd == 0:
    res += 1

print(res)

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

C_num = (diffs - (A % C)) // C
D_num = (diffs - (A % D)) // D

sc = lcm(C,D)
sum_num = (diffs - (A % sc)) // sc


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

Submission status: Wrong Answer

Solution code:
a, b, c, d = [int(v) for v in input().split()]
a = a - 1
dc = b//c - a//c
dd = b//d - a//d
dcd = b//(c*d) - a//(c*d)
divable = dc + dd - dcd
print(b - a - divable)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

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

count_c = (b - a) // c
count_d = (b - a) // d
s = b - a - count_c - count_d
g = lcm(c, d)

alpha = (b - a) // g

print(s + alpha)

Submission status: Wrong Answer

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

a, b, c, d = map(int, input().split())
x2 = b // c
x1 = (a - 1) // c
y2 = b // d
y1 = (a - 1) // d
t = c * d // gcd(c, d)
z2 = b // t
z1 = (a - 1) // t
print(x2, x1, y2, y1, z2, z1)
print(b - a + 1 - (x2 - x1) - (y2 - y1) + (z2 - z1))

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int, input().split())
U = b - a + 1
import math
import fractions

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

first = math.floor(b/c) - math.ceil(a/c) + 1
second = math.floor(b/d) - math.ceil(a/d) + 1
third = math.floor(b/lcm(c,d)) - math.ceil(a/lcm(c,d)) + 1

print(U - first - second + third)

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())
if A ==1:
    c=B//C
    d=B//D
else:
    c = B//C-(A-1)//C
    d = B//D-(A-1)//D
LCM = lcm(C,D)
l = B//LCM-A//LCM
print(B-A+1-c-d+l)

Submission status: Wrong Answer

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

diff = B - A + 1

num_c = diff // C
if A % C + diff % C >= C:
    num_c += 1
num_d = diff // D
if A % D + diff % D >= D:
    num_d += 1
cd = C * D // gcd(C, D)
num_cd = diff // cd
if A % cd + diff % cd >= cd:
    num_cd += 1

ans = diff - (num_c + num_d - num_cd)
print(ans)

Submission status: Wrong Answer

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

#0からわりきれる
x0 = B//C
y0 = B//D
z0 = B//(C*D)

all0 = x0+y0-z0
all0 = B-all0

#それ以下から
x1 = A//C
y1 = A//D
z1 = A//(C*D)
all1 = x1+y1-z1
all1 = A-all1


print(all0-all1)

Submission status: Wrong Answer

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

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 cn(n,x):
    return n-(n//x)

def cnt(a,b,x):
    return cn(b+1,x) - cn(a,x)

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

# print(E)
# print(cnt(A,B,C))
# print(cnt(A,B,D))
# print(cnt(A,B,E))

print(cnt(A,B,C)+cnt(A,B,D)-cnt(A,B,E))

Submission status: Wrong Answer

Solution code:
import fractions
import math
a,b,c,d=map(int,input().split())
k=c*d//fractions.gcd(c,d)
ans=b-a+1
ca=math.ceil(a/c)
cb=math.floor(b/c)
da=math.ceil(a/d)
db=math.floor(b/d)
ka=math.ceil(a/k)
kb=math.floor(b/k)
ans-=cb-ca+1
ans-=db-da+1
ans+=kb-ka+1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, C, D = MAP()

num_C_yaku = B//C - (A-1)//C
num_D_yaku = B//D - (A-1)//D
num_CD_yaku = int(B//(C*D/gcd(C, D)) - (A-1)//(C*D/gcd(C, D)))

print((B-A+1)-(num_C_yaku+num_D_yaku-num_CD_yaku))

Submission status: Wrong Answer

Solution code:
import sys
# input = sys.stdin.readline

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

def divup(a, b):
    return (a + b - 1) // b

ans = 0
ans += divup(B, C)
ans -= divup(A - 1, C)
# print("#", ans)
ans += divup(B, D)
ans -= divup(A - 1, D)
# print("#", ans)
#
ans -= divup(B, C * D)
ans += divup(A - 1, C * D)
# print("#", ans)

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