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
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

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

def lcm(a, b):
    return a // gcd(a, b) * b
a,b,c,d=MI()
if c>d:
    u=lcm(c,d)
else:
    u=lcm(d,c)
#print(u)
#1~x mod y==0
def div(x,y):
    return int(x/y) 
ansb=b-div(b,c)-div(b,d)+div(b,u)
ansa=a-1-div(a-1,c)-div(a-1,d)+div(a-1,u)
print(ansb-ansa)

Submission status: Wrong Answer

Solution code:
def resolve():
    from fractions import gcd
    a, b, c, d = map(int, input().split())
    e = c*d/gcd(c,d)
    db = b - (int(b/c) + int(b/d) - int(b/e))    
    da = (a-1) - (int((a-1)/c) + int((a-1)/d) - int((a-1)/e))
    print(int(db-da))      
resolve()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

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

def lcm(a, b):
    return a // gcd(a, b) * b
a,b,c,d=MI()
if c>d:
    u=lcm(c,d)
else:
    u=lcm(d,c)
#print(u)
#1~x mod y==0
def div(x,y):
    return floor(x/y) 
ansb=b-div(b,c)-div(b,d)+div(b,u)
ansa=a-1-div(a-1,c)-div(a-1,d)+div(a-1,u)
print(ansb-ansa)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from fractions import gcd

a, b, c, d = map(int, readline().split())
print((b - a + 1) - (b // c + b // d) + ((a - 1) // c + (a - 1) // d) + b // (c * d // gcd(c, d)) - a // (c * d // gcd(c, d)))

Submission status: Wrong Answer

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

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

s = lcm(C,D)
X =  A - (A//C + A //D - A//s)
Y =  B - (B//C + B //D - B//s)
print(Y-X)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

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

def lcm(a, b):
    return a // gcd(a, b) * b
a,b,c,d=MI()
if c>d:
    u=lcm(c,d)
else:
    u=lcm(d,c)
#print(u)
#1~x mod y==0
def div(x,y):
    return floor(x/y) 
ansb=b-div(b,c)-div(b,d)+div(b,u)
ansa=a-1-div(a-1,c)-div(a-1,d)+div(a-1,u)
print(ansb-ansa)

Submission status: Wrong Answer

Solution code:
def resolve():
    from fractions import gcd
    a, b, c, d = map(int, input().split())
    e = c*d/gcd(c,d)
    db = b - (b//c + b//d - b//e)    
    da = (a-1) - ((a-1)//c + (a-1)//d - (a-1)//e)
    print(int(db-da))

      
resolve()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from fractions import gcd

a, b, c, d = map(int, readline().split())
print((b - a + 1) - (b // c + b // d) + ((a - 1) // c + (a - 1) // d) + b // (c * d // gcd(c, d)))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D = (int(x) for x in input().split())
c = 0
d = 0
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
M = lcm(C,D)
c = B//C - A//C
d = B//D - A//D
m = B//M - A//M
print(B-A+1-(c+d-m))

Submission status: Wrong Answer

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
a,b,c,d = iim()
import fractions

num = b-a+1
print(num-num//c-num//d+num//((c*d)//fractions.gcd(c,d)))

Submission status: Wrong Answer

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
a,b,c,d = iim()

def num(i):
    mulc = i//c
    muld = i//d
    mulcd = i//(c*d)
    return i-mulc-muld+mulcd

print(num(b)-num(a-1))

Submission status: Wrong Answer

Solution code:
from fractions import gcd


def main():
    A, B, C, D = [int(x) for x in input().split()]
    l = (C * D) / gcd(C, D)
    b = B - anti(B, C, D, l)
    a = (A - 1) - anti((A - 1), C, D, l)
    print(int(b - a))


def anti(x, y, z, l):
    return (x // y) + (x // z) - (x // l)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import fractions


def main():
    A, B, C, D = [int(x) for x in input().split()]
    N = B - A + 1
    g = fractions.gcd(C, D)
    l = (C * D) / g
    b = anti(B, C, D, l)
    a = anti((A-1), C, D, l)
    print(N - (b - a))


def anti(x, y, z, l):
    return int(x / y) + int(x / z) - int(x / l)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def unko(x,C,D):
  import fractions
  t=int(fractions.gcd(C,D))
  t_=C*D/t
  return x-(x//C+x//D-x//t_)
print(unko(B,C,D)-unko(A-1,C,D))

Submission status: Wrong Answer

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

def unko(x,C,D):
  import fractions
  t=fractions.gcd(C,D)
  t_=C*D/t
  return x-(x//C+x//D-x//t_)
print(int(unko(B,C,D)-unko(A-1,C,D)))

Submission status: Wrong Answer

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

def unko(x,C,D):
  import fractions
  t=fractions.gcd(C,D)
  t_=C*D/t
  return int(x-(x//C+x//D-x//t_))
print(unko(B,C,D)-unko(A-1,C,D))

Submission status: Wrong Answer

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

def unko(x,C,D):
  import fractions
  t=fractions.gcd(C,D)
  t_=C*D/t
  return x-(x//C+x//D-x//t_)
print(unko(B,C,D)-unko(A-1,C,D))

Submission status: Wrong Answer

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

def unko(x,C,D):
  import fractions
  t=fractions.gcd(C,D)
  t_=C*D/t
  return x-(int(x/C)+int(x/D)-int(x/t_))
print(unko(B,C,D)-unko(A-1,C,D))

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

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

LCM=lcm(C,D)

Cwari=(B//C)-((A-1)//C)
Dwari=(B//D)-((A-1)//D)
CDwari=(B//LCM)-(A//LCM)

print(max((B-A+1)-(Cwari+Dwari-CDwari),0))

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

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

LCM=lcm(C,D)

Cwari=(B//C)-((A-1)//C)
Dwari=(B//D)-((A-1)//D)
CDwari=(B//LCM)-(A//LCM)

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
#from math import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


a, b, c, d = Is()
def calc(num, x, y):
    l = (x*y)/gcd(x, y)
    return num - floor(num/x) - floor(num/y) + floor(num/l)

print(calc(b, c, d) - calc(a-1, c, d))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
#from math import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


a, b, c, d = Is()
def calc(num, x, y):
    l = x*y/gcd(x, y)
    return num - floor(num/x) - floor(num/y) + floor(num/l)

print(calc(b, c, d) - calc(a-1, c, d))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
#from math import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


a, b, c, d = Is()
e = c*d/gcd(c, d)
w = b-a+1
x = floor(b/c)-ceil(a/c)+1
y = floor(b/d)-ceil(a/d)+1
z = floor(b/e)-ceil(a/e)+1
# print(w, x, y, z)
print(w-x-y+z)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

div_c = b//c - a//c
div_d = b//d - a//d
lcm_cd = c*d//gcd(c, d)
div_cd = b//lcm_cd - a//lcm_cd

print(b - a + 1 - div_c - div_d + div_cd)

Submission status: Wrong Answer

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

AmimanCD = (A-1)//C + (A-1)//D - (A-1)//(C*D/fractions.gcd(C,D))
BikaCD   =  B   //C +  B   //D -  B   //(C*D/fractions.gcd(C,D))
AB_CD = round(BikaCD-AmimanCD)
print(B-A+1-AB_CD)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

ans_b = B - B//C - B//D + B//G
ans_a = A - A//C - A//D + A//G

print(ans_b - ans_a + 1)

Submission status: Wrong Answer

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

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

ans_c = (B - A) // C
ans_d = (B - A) // D
i = (B - A) // (C * D // gcd(C, D))

print(B - A - ans_c - ans_d + i)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): return k.join(list(map(str, lst)))
INF = float('inf')

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

def solve():
    a, b, c, d = MI()

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

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): return k.join(list(map(str, lst)))
INF = float('inf')

from fractions import gcd

def solve():
    a, b, c, d = MI()

    g = gcd(c, d)
    bb = b - b // c - b // d + b // g
    aa = a - a // c - a // d + a // g
    print(bb - aa)

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
from fractions import gcd

a,b,c,d = map(int,input().split())
lcm = (c*d)//gcd(c,d)
ans = 0

# 全体-（cで可+dで可-両方可）
ans += b-((b//c)+(b//d)-(b//lcm))
ans -= a-((a//c)+(a//d)-(a//lcm))

print(ans)

Submission status: Wrong Answer

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

if C == D:
    
    m = math.floor(B / C) - math.floor((A - 1) / B)
    
    print(B-A+1- m)
    
    
else:
    

    a, b = C,D
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    t = C*D/b
    
    m = math.floor(B / C) + math.floor(B / D) - math.floor(B / t)
     
    n = math.floor((A-1) / C) + math.floor((A-1) / D ) - math.floor((A-1) / t)
    
    print(B-A+1-m+n)

Submission status: Wrong Answer

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

if C == D:
    
    m = math.floor(B / C) - math.floor((A - 1) / B)
    
    print(B-A+1- m)
    
    
else:
    

    a, b = C,D
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    print(b)
    
    t = C*D/b
    
    m = math.floor(B / C) + math.floor(B / D) - math.floor(B / t)
     
    n = math.floor((A-1) / C) + math.floor((A-1) / D ) - math.floor((A-1) / t)
    
    print(B-A+1-m+n)

Submission status: Wrong Answer

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

a, b = C,D
if a < b:
    a, b = b, a
while a % b != 0:
    a, b = b, a % b
# print(b)

t = C*D/b

m = math.floor(B / C) + math.floor(B / D) - math.floor(B / t)
 
n = math.floor((A-1) / C) + math.floor((A-1) / D ) - math.floor((A-1) / t)

print(B-A+1-m+n)

Submission status: Wrong Answer

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


t = 4

m = math.floor(B / C) + math.floor(B / D) - math.floor(B / t)
 
n = math.floor((A-1) / C) + math.floor((A-1) / D ) - math.floor((A-1) / t)

print(B-A+1-m+n)

Submission status: Wrong Answer

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


t = C*D

 
m = math.floor(B / C) + math.floor(B / D) - math.floor(B / t)
 
n = math.floor((A-1) / C) + math.floor((A-1) / D ) - math.floor((A-1) / t)
 
print(B-A+1-(m-n))

Submission status: Wrong Answer

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

m = math.floor(B / C) + math.floor(B / D) - math.floor(B / (C*D))
 
n = math.floor((A-1) / C) + math.floor((A-1) / D ) - math.floor((A-1) / (C*D))
 
print(B-A+1-(m-n))

Submission status: Wrong Answer

Solution code:
def gcd(x, y):
  v = max(x, y)
  w = min(x, y)
  if v % w == 0:
    return v
  else:
    while v % w != 0:
      z = v % w
      v = w
      w = z
    return z
def lcm(x, y):
  return (x * y) // gcd(x, y)
A, B, C, D = map(int, input().split(' '))
res = 0
can_dived_c = B // C - (A - 1) // C
can_dived_d = B // D - (A - 1) // D
can_dived_both = B // lcm(C, D) - (A - 1) // lcm(C, D)
res = B - (A - 1) - can_dived_c - can_dived_d + can_dived_both
print(res)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    A, B, C, D = map(int, input().split())
    N = B-A+1
    NC = (N+C-1)//C
    ND = (N+D-1)//D
    NCD = (N+C*D+1)//(C*D)
    ans = N - NC - ND + NCD

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    A, B, C, D = map(int, input().split())
    N = B-A+1
    NC = (N+C-1)//C
    ND = (N+D-1)//D
    NCD = (N+C*D+1)//(C*D)
    ans = N - NC - ND + NCD
    print(N, NC, ND, NCD)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import fractions

A,B,C,D = map(int,input().split())
m2 = B//C - (A-1)//C
m3 = B//D - (A-1)//D
m6 = B//(C*D*fractions.gcd(C,D)) - (A-1)//(C*D*fractions.gcd(C,D))
print(B-A+1-(m2+m3-m6))

Submission status: Wrong Answer

Solution code:
import fractions

A,B,C,D = map(int,input().split())
m2 = -(-(B-A)//C)
m3 = -(-(B-A)//D)
m6 = -(-(B-A)//(C*D*fractions.gcd(C,D)))
print(B-A+1-(m2+m3-m6))

Submission status: Wrong Answer

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

# a以上b以下でnで割り切れる物の数
def f(n):
    return b//n - a//n
from fractions import gcd
lc = c*d//gcd(c,d)

print((b-a+1) - (f(c)+f(d)-f(lc)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import fractions

a,b,c,d = map(int, input().split(" "))
gcd = fractions.gcd(c, d)
lcm = c * d / gcd
bwari = b - ((int)(b/c) + (int)(b/d) - (int)(b/(lcm)))
awari = (a - 1)- ((int)((a-1)/c) + (int)((a-1)/d) - (int)((a-1)/(lcm)))
print(bwari - awari)

Submission status: Wrong Answer

Solution code:


import sys
read = sys.stdin.buffer.read # 全読み込み
readline = sys.stdin.buffer.readline # 一行読み込み
readlines = sys.stdin.buffer.readlines # 一行ずつ全読み込み
sys.setrecursionlimit(10**7) # 再帰限界変更（デフォルトは1000）

"""
# 文字列（数値変換も含む）
n = readline().rstrip() # １行に１文字列のみ
lis = readline().rstrip().split() # # １行に複数の文字列

# 数値（文字変換も含む）
n = int(readline().rstrip()) # １行に数値１個のみ
a, b, c = map(int,readline().rstrip().split()) # １行に複数の数値
A = list(map(int,readline().rstrip().split()))  # １行に複数の数値（リスト受け取り）
lis = [readline().rstrip().split() for _ in range(n)] # １行に複数の数値(m個)かつ、n行続く場合（出力は二次元リスト：[['1', '2'], ['4', '5']]）

# dとAの行が交互に並んでいる場合
s = sys.stdin.readlines()
n, k=map(int, s[0].split())
d=[]
A=[]
for i in s[1:2*k:2]:
    d.append(int(i))
for i in s[2:2*k+1:2]:
    A.append(list(map(int, i.split())))
"""

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

import fractions
f = fractions.gcd(a,b) # 最大公約数
f2 = a*b // f # 最小公倍数

# b以下で条件を満たす個数
shou1=b//c
shou2=b//d
shou3=b//f2
num_b=b-(shou1+shou2-shou3)

# a-1以下で条件を満たす個数
shou4=(a-1)//c
shou5=(a-1)//d
shou6=(a-1)//f2
num_a=(a-1)-(shou4+shou5-shou6)

print(num_b-num_a)

Submission status: Wrong Answer

Solution code:


import sys
read = sys.stdin.buffer.read # 全読み込み
readline = sys.stdin.buffer.readline # 一行読み込み
readlines = sys.stdin.buffer.readlines # 一行ずつ全読み込み
sys.setrecursionlimit(10**7) # 再帰限界変更（デフォルトは1000）

"""
# 文字列（数値変換も含む）
n = readline().rstrip() # １行に１文字列のみ
lis = readline().rstrip().split() # # １行に複数の文字列

# 数値（文字変換も含む）
n = int(readline().rstrip()) # １行に数値１個のみ
a, b, c = map(int,readline().rstrip().split()) # １行に複数の数値
A = list(map(int,readline().rstrip().split()))  # １行に複数の数値（リスト受け取り）
lis = [readline().rstrip().split() for _ in range(n)] # １行に複数の数値(m個)かつ、n行続く場合（出力は二次元リスト：[['1', '2'], ['4', '5']]）

# dとAの行が交互に並んでいる場合
s = sys.stdin.readlines()
n, k=map(int, s[0].split())
d=[]
A=[]
for i in s[1:2*k:2]:
    d.append(int(i))
for i in s[2:2*k+1:2]:
    A.append(list(map(int, i.split())))
"""

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

num=b-a+1
shou1=num//c
shou2=num//d
shou3=num//(c*d)

print(num-(shou1+shou2-shou3))

Submission status: Wrong Answer

Solution code:
import fractions

a,b,c,d=map(int,input().split())
g=(fractions.gcd(c,d))
l=(c*d)/g
C=int(b//c)-int((a-1)//c)
D=int(b//d)-int((a-1)//d)
E=int(b//l)-int((a-1)//l)
print(b-a+1-C-D+E)

Submission status: Wrong Answer

Solution code:
import fractions

a,b,c,d=map(int,input().split())
g=fractions.gcd(c,d)
l=(c*d)/g

print(b-a+1-int(b//c)+int((a-1)//c)-int(b//d)+int((a-1)//d)+int(b//l)-int((a-1)//l))

Submission status: Wrong Answer

Solution code:
import fractions

a,b,c,d=map(int,input().split())
C=int(b//c)-int((a-1)//c)
D=int(b//d)-int((a-1)//d)
g=fractions.gcd(c,d)
l=(c*d)/g
E=int(b//l)-int((a-1)//l)
print(int(b)-int(a)+1-int(D)-int(C)+int(E))

Submission status: Wrong Answer

Solution code:
import fractions

a,b,c,d=map(int,input().split())
C=int(b//c)-int((a-1)//c)
D=int(b//d)-int((a-1)//d)
g=fractions.gcd(c,d)
l=(c*d)/g
E=int(b//l)-int((a-1)//l)
print(int(b-a+1-C-D+E))

Submission status: Wrong Answer

Solution code:
import fractions

a,b,c,d=map(int,input().split())
C=int(b//c)-int((a-1)//c)
D=int(b//d)-int((a-1)//d)
g=fractions.gcd(c,d)
l=(c*d)/g
E=int(b//l)-int((a-1)//l)
print(int(b-a+1-C-D+E))
print(C,D,E)

Submission status: Wrong Answer

Solution code:
import fractions

a,b,c,d=map(int,input().split())
C=int(b//c)-int((a-1)//c)
D=int(b//d)-int((a-1)//d)
g=fractions.gcd(c,d)
l=(c*d)/g
E=int(b//l)-int((a-1)//l)
print(int(b-a+1-C-D+E))

Submission status: Wrong Answer

Solution code:
import fractions

a,b,c,d=map(int,input().split())
C=b//c-((a-1)//c)
D=b//d-((a-1)//d)
g=fractions.gcd(c,d)
l=c*d/g
E=b//l-((a-1)//l)
print(int(b-a+1-C-D+E))

Submission status: Wrong Answer

Solution code:
from math import ceil
from fractions import gcd

a, b, c, d = map(int, input().split())
cd_lcm = c*d//gcd(c, d)
c_left, c_right = ceil(a/c), b//c
d_left, d_right = ceil(a/d), b//d
cd_left, cd_right = ceil(a/cd_lcm), b//(cd_lcm)
cv, dv, cdv = c_right - c_left + 1, d_right - d_left + 1, cd_right - cd_left + 1
print((b - a + 1) - (cv + dv - cdv))

Submission status: Wrong Answer

Solution code:
import math
import fractions
a,b,c,d = map(int,input().split())
c_d = ((c*d)/(fractions.gcd(c,d)))
#print(c_d,c*d)
a_c = (a-1) // c
a_d = (a-1) // d
a_c_d = (a-1) // c_d
a_ans = (a-1) - a_c - a_d + a_c_d
#ans1 = (a_c + a_d - a_c_d)
#print(ans1)
b_c = b // c
b_d = b // d
b_c_d = b // c_d
b_ans = b - b_c - b_d + b_c_d
#ans2 = (b_c + b_d -b_c_d)
#print(ans2)
#print(math.floor((b-a+1)-(ans2-ans1)))
print(math.floor(b_ans-a_ans))

Submission status: Wrong Answer

Solution code:
import math
import fractions
a,b,c,d = map(int,input().split())
c_d = ((c*d)/(fractions.gcd(c,d)))
#print(c_d,c*d)
a_c = (a-1) // c
a_d = (a-1) // d
a_c_d = (a-1) // c_d
a_ans = (a-1) - a_c - a_d + a_c_d
#ans1 = (a_c + a_d - a_c_d)
#print(ans1)
b_c = b // c
b_d = b // d
b_c_d = b // c_d
b_ans = b - b_c - b_d + b_c_d
#ans2 = (b_c + b_d -b_c_d)
#print(ans2)
#print(math.floor((b-a+1)-(ans2-ans1)))
print(b_ans-a_ans)

Submission status: Wrong Answer

Solution code:
import fractions
import math
a,b,c,d = map(int,input().split())
c_d = c*d/fractions.gcd(c,d)
a_c = (a-1) // c
a_d = (a-1) // d
a_c_d = (a-1) // c_d
ans1 = (a_c + a_d - a_c_d)
#print(ans1)
b_c = b // c
b_d = b // d
b_c_d = b // c_d
ans2 = (b_c + b_d -b_c_d)
#print(ans2)
print(math.floor((b-a+1)-(ans2-ans1)))

Submission status: Wrong Answer

Solution code:
import math
def gcd(a,b):
   while b != 0:
       a, b = b, a % b
       if b ==0:
           return a
A,B,C,D = map(int,input().split())
minCg = math.ceil(A/C)
maxCg = math.floor(B/C)
minDg = math.ceil(A/D)
maxDg = math.floor(B/D)
gcd = gcd(C,D) 
CD = (C*D) // gcd
minCDg = math.ceil(A/(CD))
maxCDg = math.floor(B/(CD))
Cg = maxCg - minCg +1
Dg = maxDg - minDg +1
CDg = maxCDg - minCDg +1
Anti = (Cg+Dg-CDg)
print(B-A+1-Anti)

Submission status: Wrong Answer

Solution code:
from math import ceil, floor
from fractions import gcd

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

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

divC = floor(b/c)-ceil(a/c)
divD = floor(b/d)-ceil(a/d)
res = (b-a) - (divC+divD) + floor(b/lcm(c,d))

print(res-1)

Submission status: Wrong Answer

Solution code:
from math import ceil, floor

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

divC = floor(b/c)-ceil(a/c)
divD = floor(b/d)-ceil(a/d)
res = (b-a) - (divC+divD)

print(res)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

lcm = lambda x, y: x*y // gcd(x, y)

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

b_ = b
b_ -= b // c
b_ -= b // d
b_ += b // lcm(c, d)

a_ = a - 1
a_ -= a // c
a_ -= a // d
a_ += a // lcm(c, d)


print(b_ - a_)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

lcm = lambda x, y: x*y // gcd(x, y)

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

b_ = b
b_ -= b // c
b_ -= b // d
b_ += b // lcm(c, d)

a_ = a - 1
a_ -= a_ // c
a_ -= a_ // d
a_ += a_ // lcm(c, d)


print(b_ - a_)

Submission status: Wrong Answer

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

b_ = b
b -= b // c
b -= b // d

a_ = a
a -= a // c
a -= a // d

if b_ % a_ == 0:
    b += 1

print(b - a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import fractions

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

l = (C * D) // fractions.gcd(C,D)
b_sum = B -(B//C) - (B//D) + (B//l)
a_sum = A - (A//C) - (A//D) + (A//l)

print(b_sum - a_sum)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
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)

ans=0
ans+=b//c-(a-1)//c
ans+=b//d-(a-1)//d
q=lcm(c,d)
ans+=b//q-(a-1)//q
print(ans)

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())
print(B - A + 1 - (B // C - (A - 1) // C + B // D - (A - 1) // D - (B // (lcm(C, D) - (A - 1) // lcm(C, D)))))

Submission status: Wrong Answer

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

amari_ac = a % c
amari_ad = a % d
if amari_ac == 0:
    c_min = a
else:
    c_min = a+c - amari_ac
if amari_ad == 0:
    d_min = a
else:
    d_min = a+d - amari_ad

amari_bc = b % c
amari_bd = b % d
c_max = b-amari_bc
d_max = b-amari_bd

c_count = (c_max-c_min)//c + 1
d_count = (d_max-c_min)//d + 1

lcm_cd = c*d // gcd(c, d)
amari_acd = a % lcm_cd
if amari_acd == 0:
    cd_min = a
else:
    cd_min = a+lcm_cd - amari_acd

amari_bcd = b % lcm_cd
cd_max = b - amari_bcd

cd_count = (cd_max-cd_min)//lcm_cd + 1

if cd_max < a or b < cd_max:
    cd_count = 0
if cd_min < a or cd_min > b:
    cd_count = 0

print(ans-c_count-d_count+cd_count)

Submission status: Wrong Answer

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

def calc(a,x):
    return int(a/x)

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

Submission status: Wrong Answer

Solution code:

import math
from  fractions import gcd

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

A,B,C,D = map(int,input().split())
d_cnt = math.floor(B/D)-math.floor((A-1)/D)
c_cnt = math.floor(B/C)-math.floor((A-1)/C)
cd = lcm(C,D)
cd_cnt = math.floor(B/cd)-math.floor((A-1)/cd)
print(B-A+1-(c_cnt+d_cnt-cd_cnt))

Submission status: Wrong Answer

Solution code:
import math
from  fractions import gcd

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

A,B,C,D = map(int,input().split())
M1 = math.floor( B / C ) + math.floor( B / D )
M2 = math.floor( (A-1) / C ) + math.floor( (A-1) / D)
N1 = math.floor( B / lcm(C,D) )
N2 = math.floor( (A-1) / lcm(C,D) )

print(B-A+1-(M1-M2-N1+N2))