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: Runtime Error

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

gcd = 0
e = c
f = d
if e > f:
  e, f = f, e
while (True):
  r = f % e
  if r == 0:
    gcd = e
    break
  else:
    e, f = r, e

bac = int((b - a) / c)
bad = int((b - a) / d)
bal = int((b - a) / l)
result = (b - a + 1) - (bac + bad - bal)

print(result)

Submission status: Runtime Error

Solution code:
import math
input = list(map(int,input().split()))
A = input[0]
B = input[1]
C = input[2]
D = input[3]

betweenAandB = B-A+1

cA = math.ceil(A/C)
cB = int(B/C)
cDiv = cB - cA + 1

dA = math.ceil(A/D)
dB = int(B/D)
dDiv = dB - dA + 1

GCD = math.gcd(C,D)
LCM = C*D/GCD

lcmA = math.ceil(A/LCM)
lcmB = int(B/LCM)
lcmDiv = max(lcmA, lcmB) - min(lcmA, lcmB) + 1

ans = betweenAandB - cDiv - dDiv + lcmDiv
print(ans)

Submission status: Runtime Error

Solution code:
import math
input = list(map(int,input().split()))
A = input[0]
B = input[1]
C = input[2]
D = input[3]

betweenAandB = B-A+1

cA = math.ceil(A/C)
cB = int(B/C)
cDiv = cB - cA + 1

dA = math.ceil(A/D)
dB = int(B/D)
dDiv = dB - dA + 1

GCD = math.gcd(C,D)
LCM = C*D/GCD

lcmA = math.ceil(A/LCM)
lcmB = int(B/LCM)
lcmDiv = max(lcmA, lcmB) - min(lcmA, lcmB) + 1

ans = betweenAandB - cDiv - dDiv + lcmDiv
print(betweenAandB)
print(cDiv)
print(dDiv)
print(lcmDiv)
print(ans)

Submission status: Runtime Error

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)

e=lcm(c,d)
a,b,c,d=map(int,input().split())
print((b-a+1)-(b//c-a//c)-(b//d-a//d)+(b//e-a//e))

Submission status: Runtime Error

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

 
def lcm(x,y):
  return x*y/gcd(x,y)
 
def numantidiv(a,b,c):
    r=a-a/b-a/c+(a/lcm(b,c)
    return r
 
a,b,c,d=(int(x) for x in input().split())
ans=numantidiv(b,c,d)-numantidiv(a-1,c,d)
print(ans)

Submission status: Runtime Error

Solution code:
import re
import sys
import math
import itertools
from sys import stdin

def main():
    """
     解答をこちらに
    """
    a, b, c, d = list(map(int, input().split()))
    l = list(range(a,b))
    ans = 0

    for i in l:
        if i%c!=0 and i%d!=0:
            ans += 1
    print(ans)
    pass


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <algorithm>
#include <numeric>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

ll gcd(ll a, ll b)
{
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

ll f(ll A, ll C, ll D)
{
    return A - (A / C) - (A / D) + A / lcm(C, D);
}

int main()
{
    ll A, B, C, D, ans;
    cin >> A >> B >> C >> D;

    cout << f(B, C, D) - f(A - 1, C, D) << endl;

    return 0;
}

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [],
   "source": [
    "def gcd(a,b):\n",
    "    while b!=0:\n",
    "        a,b=b,a%b\n",
    "    return a\n",
    "\n",
    " #最小公倍数\n",
    "def lcm(a,b):\n",
    "    return a*b/gcd(a,b)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10 40 6 8\n",
      "24.0\n",
      "23\n"
     ]
    }
   ],
   "source": [
    "A,B,C,D=map(int,input().split())\n",
    "\n",
    "if A%C == 0:\n",
    "    AC = int(A/C) - 1\n",
    "else:\n",
    "    AC = int(A/C)\n",
    "if A%D == 0:\n",
    "    AD = int(A/D) - 1\n",
    "else:\n",
    "    AD = int(A/D)\n",
    "    \n",
    "lcmCD = lcm(C,D)\n",
    "if A%(lcmCD) == 0:\n",
    "    ACD = int(A/(lcmCD)) - 1\n",
    "else:\n",
    "    ACD = int(A/(lcmCD))\n",
    "    \n",
    "print((B - A + 1) - (int(B/C) - AC + int(B/D) - AD - int(B/(lcmCD) + ACD)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}

Submission status: Runtime Error

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

if A%C == 0:
    AC = int(A/C) - 1
else:
    AC = int(A/C)
if A%D == 0:
    AD = int(A/D) - 1
else:
    AD = int(A/D)
    
lcm = (C*D)/math.gcd(C,D)
if A%(lcm) == 0:
    ACD = int(A/(lcm)) - 1
else:
    ACD = int(A/(lcm))

print((B - A + 1) - (int(B/C) - AC + int(B/D) - AD - int(B/(lcm) + ACD)))

Submission status: Runtime Error

Solution code:
import math
a, b, c, d = map(int, input().split())
cCan = b//c-(a-1)//c
dCan = b//d-(a-1)//d
cdSK = c*d//math.gcd(c, d)
cdCan = b//cdSK-(a-1)//cdSK
print(int(b-(a-1)-cCan-dCan+cdCan))

Submission status: Runtime Error

Solution code:
import math

a,b,c,d=map(int,input().split())
cn1=0
cn2=0
cn3=0
an1=0
an2=0
an3=0
cnt=0
ans=0
lm=(c*d)//math.gcd(c,d)

#bまで
cn1=b//c
cn2=b//d
cn3=b//lm
#aまで
an1=(a-1)//c
an2=(a-1)//d
an3=(a-1)//lm
#aからbまで
cn1=cn1-an1
cn2=cn2-an2
cn3=cn3-an3

cnt=cn1+cn2-cn3
ans=b-a-cnt

print(ans+1)

Submission status: Runtime Error

Solution code:
from math import floor
 
def gcm(x,y):
  r=x%y
  while r==0:
    x=y
    y=r
    r=x%y
  return y
 
def lcm(x,y):
  return x*y/gcm(x,y)
 
def numantidiv(a,b,c):
    r=a-floor(a/b)+floor(a/c)-floor(a/lcm(b,c))
    return r
 
a,b,c,d=(int(x) for x in input().split())
ans=numantidiv(b,c,d)-numantidiv(a-1,c,d)
print(ans)

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int,input().split())
def lcm(x,y):
    return (x*y)//math.gcd(x,y)
lm=lcm(c,d)
print(lm)

Submission status: Runtime Error

Solution code:
import math
def lcm(x,y):
  return x*y/math.gcd(x,y)
def numantidiv(x,y,z):
    r=x-math.floor(x/y)-math.floor(x/z)+math.floor(x/lcm(y,z))
    return r

a,b,c,d=map(int, input().split())
ans=numantidiv(b,c,d)-numantidiv(a-1,c,d)
print(ans)

Submission status: Runtime Error

Solution code:
import math

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

a,b,c,d=map(int,input().split())
cn1=0
cn2=0
cn3=0
an1=0
an2=0
an3=0
cnt=0
ans=0
lm=lcm(c,d)

#bまで
cn1=b//c
cn2=b//d
cn3=b//lm
#aまで
an1=(a-1)//c
an2=(a-1)//d
an3=(a-1)//lm
#aからbまで
cn1=cn1-an1
cn2=cn2-an2
cn3=cn3-an3

cnt=cn1+cn2-cn3
ans=b-a-cnt

print(ans+1)

Submission status: Runtime Error

Solution code:

import math
a,b,c,d=map(int,input().split())
cnt=0
ccnt=b//c-(a-1)//c
dcnt=b//d-(a-1)//d
cdgcd=math.gcd(c,d)

def lcm(x, y):
    return (x * y) // math.gcd(x, y)
cdlcm=lcm(c,d)


print(int(b-a-(ccnt+dcnt-b//(c*d/cdgcd))+1))

Submission status: Runtime Error

Solution code:
import math
def lcm(x,y):
  return x*y/math.gcd(x,y)
def numantidiv(a,b,c):
    r=a-math.floor(a/b)-math.floor(a/c)+math.floor(a/lcm(b,c))
    return r

a,b,c,d=map(int, input().split())
ans=numantidiv(b,c,d)-numantidiv(a-1,c,d)
print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
import math
def lcm(x,y):
  return x*y/math.gcd(x,y)
def numantidiv(a,b,c):
    r=a-math.floor(a/b)-math.floor(a/c)+math.floor(a/lcm(b,c))
    return r

a,b,c,d=[int(x) for x in stdin.readline().rstrip().split()]
ans=numantidiv(b,c,d)-numantidiv(a-1,c,d)
print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
import math
def lcm(x,y):
  return x*y/math.gcd(x,y)
def numantidiv(a,b,c):
    r=a-math.floor(a/b)-math.floor(a/c)+math.floor(a/lcm(b,c))
    return r

a,b,c,d=int(stdin.readline().rstrip().split())
ans=numantidiv(b,c,d)-numantidiv(a-1,c,d)
print(ans)

Submission status: Runtime Error

Solution code:
import math
def lcm(x,y):
  return x*y/math.gcd(x,y)
def numantidiv(a,b,c):
    r=a-math.floor(a/b)-math.floor(a/c)+math.floor(a/lcm(b,c))
    return r

a,b,c,d=(int(x) for x in input().split())
ans=numantidiv(b,c,d)-numantidiv(a-1,c,d)
print(ans)

Submission status: Runtime Error

Solution code:
import math

def lcm(x,y):
  return x*y/math.gcd(x,y)
 
def numantidiv(a,b,c):
    r=a-math.floor(a/b)-math.floor(a/c)+math.floor(a/lcm(b,c))
    return r

a,b,c,d=(int(x) for x in input().split())
ans=numantidiv(b,c,d)-numantidiv(a-1,c,d)
print(ans)

Submission status: Runtime Error

Solution code:
import math

def lcm(x,y):
  return x*y/math.gcd(x,y)
 
def numantidiv(a,b,c):
    r=a-math.floor(a/b)-math.floor(a/c)+math.floor(a/lcm(b,c))
    return r

a,b,c,d=(int(x) for x in input().split())
ans=numantidiv(b,c,d)-numantidiv(a-1,c,d)
print(ans)

Submission status: Runtime Error

Solution code:
from math import floor
 
def gcm(x,y):
  r=x%y
  while r==0:
    x=y
    y=r
    r=x%y
  return y
 
def lcm(x,y):
  return x*y/gcm(x,y)
 
def numantidiv(a,b,c):
    r=floor(a/b)+floor(a/c)-floor(a/lcm(b,c))
    return r

a,b,c,d=(int(x) for x in input().split())
ans=numantidiv(b,c,d)-numantidiv(a-1,c,d)
print(ans)

Submission status: Runtime Error

Solution code:
from math import floor

def gcm(x,y):
  r=x%y
  while r==0:
    x=y
    y=r
    r=x%y
  return y

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

a=int(input())
b=int(input())
c=int(input())
d=int(input())

ans=b-a+1
e=floor(a/c)
while 1:
  e+=c
  if e>b:
    break
  ans--

e=floor(a/d)
while 1:
  e+=d
  if e>b:
    break
  ans--

lcm=lcm(c,d)
e=floor(a/gcm)
while 1:
  e+=lcm
  if e>b:
    break
  ans++

print(ans)

Submission status: Runtime Error

Solution code:
import math

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

def hantei(A,B,C,D):
    if (A%C==0 or A%D==0) and (B%C==0 or B%D==0):
        return False
    return True

a,b,c,d=map(int,input().split())
cn1=0
cn2=0
cn3=0
an1=0
an2=0
an3=0
cnt=0
ans=0
lm=lcm(c,d)

#bまで
cn1=b//c
cn2=b//d
cn3=b//lm
#aまで
an1=a//c
an2=a//d
an3=a//lm
#aからbまで
cn1=cn1-an1
cn2=cn2-an2
cn3=cn3-an3

cnt=cn1+cn2-cn3
ans=b-a-cnt

if hantei(a,b,c,d):
    ans+=1

print(ans)

Submission status: Runtime Error

Solution code:
import math

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

# get lcm which will be i*c
#i = 0
#flg = True

#while (flg):
#  i += 1
#  flg = ((c * i) % d != 0)
  

lcm = c * d / math.gcd(c, d)
ac = int((a - 1)/c)
ad = int((a - 1)/d)
bc = int(b/c)
bd = int(b/d)
al = int((a - 1)/lcm)
bl = int(b/lcm)

div_able = (bc - ac) + (bd - ad) - (bl - al)
div_disable = (b - a + 1) - div_able

print(div_disable)

Submission status: Runtime Error

Solution code:
inputs = input().split()
a = inputs[0]
b = inputs[1]
c = inputs[2]
d = inputs[3]

count = 0

for i in range(a, b+1):
    if i%c != 0:
        if i%d !=0:
            count = count + 1

print(count)

Submission status: Runtime Error

Solution code:
inputs = input().split()
a = inputs[0]
b = inputs[1]
c = inputs[2]
d = inputs[3]

count = 0

for i in range(a, b+1):
    if i%c != 0:
        if i%d !=0:
            count = couont + 1

print(count)

Submission status: Runtime Error

Solution code:
inputs = input().split()
a = inputs[0]
b = inputs[1]
c = inputs[2]
d = inputs[3]

count = 0

for i in range(a, b+1):
    if i%c != 0 and i%d != 0:
        count = couont + 1

print(count)

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<vector>
#include<bitset>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<list>
#include<queue>
#include<map>
#include<numeric>
using namespace std;
#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)
int INF=1e9;
const long long mod=1e9+7;
typedef long long ll;

int main(){
  ll A,B,C,D;
  cin>>A>>B>>C>>D;
  D=max(C,D),C=min(C,D);
  ll E=__gcd(C,D);
  ll lcm=C*D/E;
  ll F=(A-1)/C;
  ll G=B/C;
  ll H=(A-1)/D;
  ll I=B/D;
  ll J=(A-1)/lcm;
  ll K=B/lcm;
  cout<<(B-A+1)-(G-F)-(I-H)+(K-J)<<endl;
  return 0;
}

Submission status: Runtime Error

Solution code:
from math import floor
from math import ceil
from math import gcd
a, b, c, d = tuple(int(i) for i in input().split(" "))


def num_divided_in_n(n):
    return (floor(b / n) * n - ceil(a / n) * n) / n + 1


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


print(int(b - a + 1 - (num_divided_in_n(c) +\
                       num_divided_in_n(d) - num_divided_in_n(lcm(c, d)))))

Submission status: Runtime Error

Solution code:
from math import floor
from math import ceil
from math import gcd
a, b, c, d = tuple(int(i) for i in input().split(" "))


def num_divided_in_n(n):
    return (floor(b / n) * n - ceil(a / n) * n) / n + 1


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


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

Submission status: Runtime Error

Solution code:
import math

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


a,b,c,d = map(int,input().split(' '))
not_a_1 =0
not_b = 0
not_b =  b-(b//c)-(b//d)+(b//lcm(c,d))
not_a_1 = a-1-((a-1)//c)-((a-1)//d)+((a-1)//lcm(c,d))

print(not_b-not_a_1)

Submission status: Runtime Error

Solution code:
import math

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


a,b,c,d = map(int,input().split())
not_a_1 =0
not_b = 0
not_b =  b-(b//c)-(b//d)+(b//lcm(c,d))
not_a_1 = a-1-((a-1)//c)-((a-1)//d)+((a-1)//lcm(c,d))

print(not_b-not_a_1)

Submission status: Runtime Error

Solution code:
import math

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


a,b,c,d = map(int,input().split())
not_a_1 =0
not_b = 0
not_b =  b-(b//c)-(b//d)+(b//lcm(c,d))
not_a_1 = a-(a//c)-(a//d)+(a//lcm(c,d))

print(not_b-not_a_1)

Submission status: Runtime Error

Solution code:
import math

def main():
    A, B, C, D = map(int, input().split())
    res = B - A
    print(res - (res // C) - (res // D) + (res // lcm(C, D)))
    
def lcm(C, D):
    return int(C * D // math.gcd(C, D))

main()

Submission status: Runtime Error

Solution code:
import math

def main():
    A, B, C, D = map(int, input().split())
    res = B - A
    resByC = res // C
    resByD = res // D
    lcmRes = lcm(C, D)
    print(res - resByD - resByC + (res // lcmRes))

def lcm(C, D):
    return int(C * D // math.gcd(C, D))

main()

Submission status: Runtime Error

Solution code:
def main():
    A, B, C, D = map(int, input().split())
    res = B - A
    resByC = res // C
    resByD = res // D
    lcmRes = lcm(C, D)
    print(res - resByD - resByC + (res // lcmRes))

def gcd(C, D):
    x = max(C, D)
    y = min(C, D)
    if x % y == 0:
        return 0
    else:
        while x % y != 0:
             z = x % y
             x = y
             y = z
        else:
            return z

def lcm(C, D):
    return int(C * D // gcd(C, D))

main()

Submission status: Runtime Error

Solution code:
x,a = map(int,input().split())

if x<a:
    print(0)
else:
    print(10)

Submission status: Runtime Error

Solution code:
from math import gcd

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

c = (B // C) - (A // C) + int(A % C == 0)
d = (B // D) - (A // D) + int(A % D == 0)
lcm_cd = (C * D) // gcd(C, D)
cd = (B // (lcm_cd)) - (A // (lcm_cd)) + int(A % (lcm_cd) == 0)

c_or_d = c + d - cd

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

Submission status: Runtime Error

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

c = (B // C) - (A // C) + int(A % C == 0)
d = (B // D) - (A // D) + int(A % D == 0)
lcm_cd = (C * D) // gcd(C, D)
cd = (B // (lcm_cd)) - (A // (lcm_cd)) + int(A % (lcm_cd) == 0)

c_or_d = c + d - cd

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

Submission status: Runtime Error

Solution code:
A,B,C,D=map(int,input().split())
import fractions
E=(C * D) //fractions.gcd(C, D)
c=1/C
d=1/D
e=1/E
C_min=int(A*c)+1
C_max=int(B*c)
D_min=int(A*d)+1
D_max=int(B*d)
CD_min=int(A*e)+1
CD_max=int(B*e)+1
print(B-A-1-M)

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int a,b,c,d;
  cin >> a >> b >> c >> d;
  long long int cn = b/c - (a-1)/c;
  long long int dn = b/d - (a-1)/c;
  long long int cdn = b/(c*d) - (a-1)/(c*d);
  cout << (b-a+1) -cn - dn + cdn << endl;
}

Submission status: Runtime Error

Solution code:
from sys import exit
import math

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

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

c_sum = B // C - (A - 1) // C
d_sum = B // D - (A - 1) // D
cd_sum = B // CD - (A - 1) // CD

print(B - A + 1 - (c_sum + d_sum - cd_sum))

Submission status: Runtime Error

Solution code:
import math
a,b,c,d=list(map(int, input().split()))
lcm=int(c*d/math.gcd(c,d))
could_divide=(b//c-(a-1)//c) + (b//d-(a-1)//d) - (b//lcm-(a-1)//lcm)
#print("could divide by "+str(c)+" : "+str(b//c-(a-1)//c))
#print("could divide by "+str(d)+" : "+str(b//d-(a-1)//d))
print(b-a+1-could_divide)

Submission status: Runtime Error

Solution code:
mport fractions
 
a,b,c,d = map(int,input().split())
 
ans = 0
 
if c % d == 0:
    print((b - a + 1) - ((b)//d - (a-1)//d))
elif d % c == 0:
    print((b - a + 1) - ((b)//c - (a-1)//c))
else:
    tot = c * d // fractions.gcd(c, d)
    tmp = ((b) // d - (a-1) // d) + ((b)//c - (a-1)//c) - ((b) // tot - (a-1) // tot)
    print(int((b - a + 1) - tmp))

Submission status: Runtime Error

Solution code:
import math
a,b,c,d=map(int,input().split())
ans=b-a+1
ans-=b//c-(a-1)//c
ans-=b//d-(a-1)//d
e=math.gcd(a,b)
ans+=b//e-(a-1)//e
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
A,B,C,D=list(map(int,input().split()))
def Factoring(value):
    _value=value
    div=2
    data=[]
    while value!=1:
        while value%div==0:
            value=int(value/div)
            data.append(div)
        div+=1
    return(data)
def divcheck(value,lst):
    for i in lst:
        if value%i!=0:
            return(1)
        value=int(value/i)
    return(0)
FactoringC,FactoringD=Factoring(C),Factoring(D)
for i in range(A,B+1):
    if not divcheck(i,FactoringC):
        startC=i
        break
for i in range(A,B+1):
    if not divcheck(i,FactoringD):
        startD=i
        break
print(B+1-A-len(set(list(range(startC,B+1,C))+list(range(startD,B+1,D)))))

Submission status: Runtime Error

Solution code:
A,B,C,D = input().split()
count = 0
start = int(A)
finish = int(B)
ite = 100
for i in range(ite):
  if i == ite-1:
    nums = list(range(start *i, finish ))
  else:
    nums = list(range(start *i, start*(i+1) ))
  tmp = [x for x in nums if not x%int(C) == 0 and not x%int(D) == 0]
  count += len(tmp)
print(count)

Submission status: Runtime Error

Solution code:
import math
x = input().split()


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


a = (int(x[0])-1) // int(x[2])
b = (int(x[0])-1) // int(x[3])
a1 = int(x[1]) // int(x[2])
b1 = int(x[1]) // int(x[3])
a11 = (int(x[0])-1) // lcm(int(x[2]), int(x[3]))
a12 = int(x[1]) // lcm(int(x[2]), int(x[3]))
print(int(x[1]) - int(x[0]) - (a1 - a) - (b1 - b) + (a12 - a11)+1)

Submission status: Runtime Error

Solution code:
A,B,C,D = input().split()
count = 0
start = int(A)
finish = int(B)
ite = finish//start
for i in range(ite):
  if i == ite-1:
    nums = list(range(start *i, finish ))
  else:
    nums = list(range(start *i, start*(i+1) ))
  tmp = [x for x in nums if not x%int(C) == 0 and not x%int(D) == 0]
  count += len(tmp)
print(count)

Submission status: Runtime Error

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

import math

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

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

# A〜Bのうち、C, Dで割り切れる数の個数を求める
C_yakusuu = math.floor(B / C) - math.ceil(A / C) + 1
D_yakusuu = math.floor(B / D) - math.ceil(A / D) + 1

# A〜Bのうち、CとDの公倍数の個数を求める
LCM = lcm(C, D)
LCM_yakusuu = math.floor(B / LCM) - math.ceil(A / LCM) + 1

print(B - A + 1 - (C_yakusuu + D_yakusuu - LCM_yakusuu))

Submission status: Runtime Error

Solution code:
import math

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

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

# A〜Bのうち、C, Dで割り切れる数の個数を求める
C_yakusuu = math.floor(B / C) - math.ceil(A / C) + 1
D_yakusuu = math.floor(B / D) - math.ceil(A / D) + 1

# A〜Bのうち、CとDの公倍数の個数を求める
LCM = lcm(C, D)
LCM_yakusuu = math.floor(B / LCM) - math.ceil(A / LCM) + 1

print(B - A + 1 - (C_yakusuu + D_yakusuu - LCM_yakusuu))

Submission status: Runtime Error

Solution code:
import math
A, B, C, D = map(int, input().split())
G = C * D // math.gcd(C, D)
ag = (A - 1) // G
ac = (A - 1) // C
ad = (A - 1) // D
bg = B // G
bc = B // C
bd = B // D
print((B - A + 1) - ((bc + bd - bg) - (ac + ad - ag)))

Submission status: Runtime Error

Solution code:
a, b, c, d = map(int, input().split())
 
count = b - a
def baisuu(n):
    i1 = (a // n + bool(a % n or b % n))
    i2 = (b // n)
    return int(i2 - i1)
 
def gcd(x1, x2):
    x = x1 * x2
    r = x2 % x1
    while r != 0:
        x2 = x1
        x1 = r
        r = x2 % x1
print(count - baisuu(c) - baisuu(d) + baisuu(gcd(c, d)))

Submission status: Runtime Error

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

import math

def num(N,c,d):
    lcm = (c*d)//math.gcd(c,d)
    return N - (N//c) - (N//d) +  N//lcm

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

Submission status: Runtime Error

Solution code:
import math

A,B,C,D=map(int,input().split())
c=B//C-(A-1)//C 
d=B//D-(A-1)//D 
l=C*D/math.gcd(C,D)
cd=B//l-(A-1)//l
print(int(B-(A-1)-c-d+cd))

Submission status: Runtime Error

Solution code:

# -*- coding: utf-8 -*-
# @Date    : 2019-06-24 21:31:07
# @Author  : raj lath (oorja.halt@gmail.com)
# @Link    : link
# @Version : 1.0.0

import sys
from math import gcd
sys.setrecursionlimit(10**5+1)

inf     =  int(10 ** 20)
max_val =  inf
min_val = -inf

RW  = lambda : sys.stdin.readline().strip()
RI  = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]


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


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


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


num1 = B // C - (A - 1) // C
num2 = B // D - (A - 1) // D
num3 = B // lcm(C, D) - (A - 1) // lcm(C, D)


print(B - A + 1 - (num1 + num2 - num3))

Submission status: Runtime Error

Solution code:

# -*- coding: utf-8 -*-
# @Date    : 2019-06-24 21:31:07
# @Author  : raj lath (oorja.halt@gmail.com)
# @Link    : link
# @Version : 1.0.0

import sys
from math import gcd
sys.setrecursionlimit(10**5+1)

inf     =  int(10 ** 20)
max_val =  inf
min_val = -inf

RW  = lambda : sys.stdin.readline().strip()
RI  = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]


a, b, c, d = RMI()
lcm = (c * d) // gcd(c, d)
if b // lcm == 0: common = 0
else: common = b//lcm-(a-1)//lcm

if b // c == 0:a_div = 0
else: a_div =  b // c - ( a - 1) // c
if b //d == 0: b_div = 0
else: b_div = b // d - ( a - 1) // d

ans = (b - a + 1) - a_div - b_div + common
print(int(ans))

Submission status: Runtime Error

Solution code:

# -*- coding: utf-8 -*-
# @Date    : 2019-06-24 21:31:07
# @Author  : raj lath (oorja.halt@gmail.com)
# @Link    : link
# @Version : 1.0.0

import sys
from math import gcd
sys.setrecursionlimit(10**5+1)

inf     =  int(10 ** 20)
max_val =  inf
min_val = -inf

RW  = lambda : sys.stdin.readline().strip()
RI  = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]


a, b, c, d = RMI()
lcm = (c * d) / gcd(c, d)
a_div = b // c - ( a - 1) // c
b_div = b // d - ( a - 1) // d
common= b // lcm - (a - 1) // lcm
ans = (b - a + 1) - (a_div + b_div - common)
print(int(ans))

Submission status: Runtime Error

Solution code:
A, B, C, D = list(map(int, input().split()))
from math import gcd
e = C * D // gcd(C, D)
p1 = B-A+1
p2 = (B//C) + (B//D) - (B//e)
p3 = ((A-1)//C) + ((A-1)//D) - ((A-1)//e)
print(p1 + p3 - p2)

Submission status: Runtime Error

Solution code:
A, B, C, D = list(map(int, input().split()))
from functools import gcd
e = C * D // gcd(C, D)
p1 = B-A+1
p2 = (B//C) + (B//D) - (B//e)
p3 = ((A-1)//C) + ((A-1)//D) - ((A-1)//e)
print(p1 + p3 - p2)

Submission status: Runtime Error

Solution code:
#最大公約数(ユークリッドの互余法)
def euclid_gcd(a,b):
    while b:
        a, b = b, a%b
    return a

#最小公倍数(ユークリッドの互余法)
def euclid_lcm(a, b):
    return a * b // euclid_gcd(a, b)
    
A,B,C,D = map(int,input().split())

X = euclid_lcm(C,D)
A = A-1

Y = A//C + A//D - A//X
Z = B//C + B//D - B//X
 
print(B-Z - (A-Y)

Submission status: Runtime Error

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

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

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

print(B - A + 1 - c_num - d_num + cd_num)

Submission status: Runtime Error

Solution code:
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
    
S = list(map(int, input().split()))
a1 = S[1] - S[0]
a2 = a1 // S[2]
a3 = a1 // S[3]
a4 = a1 // lcm(S[2],S[3])

ans = a1-a2-a3+a4
print(ans)

Submission status: Runtime Error

Solution code:
import math

A,B,C,D=map(int,input().split())
lcm=int(C*D/math.gcd(C,D))

if B//lcm==0:
    num_CD=0
else:
    num_CD=B//lcm-math.ceil(A/lcm)+1


if B//C==0:
    num_C=0
else:
    num_C=B//C-math.ceil(A/C)+1



if B//D==0:
    num_D=0
else:
    num_D=B//D-math.ceil(A/D)+1


ans=B-A+1-num_C-num_D+num_CD


print(int(ans))

Submission status: Runtime Error

Solution code:
A,B,C,D=map(int,input().split())
lcm=int(C*D/math.gcd(C,D))

if B//lcm==0:
    num_CD=0
else:
    num_CD=B//lcm-math.ceil(A/lcm)+1


if B//C==0:
    num_C=0
else:
    num_C=B//C-math.ceil(A/C)+1



if B//D==0:
    num_D=0
else:
    num_D=B//D-math.ceil(A/D)+1


ans=B-A+1-num_C-num_D+num_CD


print(int(ans))

Submission status: Runtime Error

Solution code:
import math

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


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


num1 = math.floor(B / C) - math.floor((A - 1) / C)
num2 = math.floor(B / D) - math.floor((A - 1) / D)
num3 = math.floor(B / lcm(C, D)) - math.floor((A - 1) / lcm(C, D))


print(B - A + 1 - (num1 + num2 - num3))

Submission status: Runtime Error

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


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


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

x = floor(B / C)
y = floor(B / D)
z = floor(B / LCM)
ans = B-x-y+z

x = floor((A-1) / C)
y = floor((A-1) / D)
z = floor((A - 1) / LCM)

ans -= (A - 1) - x - y + z

print(ans)

Submission status: Runtime Error

Solution code:
from math import floor, ceil, gcd


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


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

multiple_of_C = floor(B / C) - ceil(A / C) + 1
multiple_of_D = floor(B / D) - ceil(A / D) + 1
multiple_of_CtimesD = floor(B / LCM) - ceil(A / LCM) + 1

print((B-A+1)-multiple_of_C-multiple_of_D+multiple_of_CtimesD)

Submission status: Runtime Error

Solution code:
import fraction

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

def multiple(A, B, C): #number of multiples of C between A and B
    return int((B+0.5)//C - (A-0.5)//C)

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

allnumbers = B-A+1

ans = allnumbers - (multiple(A,B,C) + multiple(A,B,D) - multiple(A,B,lcm(C,D)))

print(ans)

Submission status: Runtime Error

Solution code:
import math

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

def multiple(A, B, C): #number of multiples of C between A and B
    return int((B+0.5)//C - (A-0.5)//C)

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

allnumbers = B-A+1

ans = allnumbers - (multiple(A,B,C) + multiple(A,B,D) - multiple(A,B,lcm(C,D)))

print(ans)

Submission status: Runtime Error

Solution code:
import math
A, B, C, D = map(int, input().split())
bc = B // C
bd = B // D
ac = (A - 1) // C
ad = (A - 1) // D
def lcm(C, D):
    return (C * D) // math.gcd(C, D)
bcd = B // lcm(C, D)
acd = (A - 1) // lcm(C, D)
a = bc - ac
b = bd - ad
c = bcd - acd
print((B + 1 - A) - (a + b - c))

Submission status: Runtime Error

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


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

size=B

cd=lcm(C,D)
allC=size//C
allD=size//D
allcd=size//cd
ALL=size-(allC+allD-allcd)

size=A-1
cd=lcm(C,D)
pC=size//C
pD=size//D
pcd=size//cd
P=size-(pC+pD-pcd)

print(ALL-P)

Submission status: Runtime Error

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


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


#print(len([x for x in range(A,B) if x%2!=0 and x%3!=0]))

size=B

cd=lcm(C,D)
allC=size//C
allD=size//D
allcd=size//cd
ALL=size-(allC+allD-allcd)

size=A-1
cd=lcm(C,D)
pC=size//C
pD=size//D
pcd=size//cd
P=size-(pC+pD-pcd)

print(ALL-P)

Submission status: Runtime Error

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

Submission status: Runtime Error

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


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


#print(len([x for x in range(A,B) if x%2!=0 and x%3!=0]))

size=B-A+1
C2=size//C

D2=size//D

cd=lcm(C,D)
cd=size//cd

Q=size-(C2+D2-cd)
print(Q)

Submission status: Runtime Error

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


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


#print(len([x for x in range(A,B) if x%2!=0 and x%3!=0]))

size=B-A+1
#C
C2=A%C
if C2 is 0:
    Csize=size
else:
    C2=C-C2
    Csize=size-C2

#D
D2=A%D
if D2 is 0:
    Dsize=size
else:
    D2=D-D2
    Dsize=size-D2

cd =lcm(C,D)

#c,dの最小公倍数
cd2=A%cd
if cd2 is 0:
    CDsize=size
else:
    cd2=cd-cd2
    CDsize=size-cd2

#Cの個数
Cq=(Csize-1)//C

#Dの個数
Dq=(Dsize-1)//D

#CDの個数
CDq=(CDsize-1)//cd


Q=(Cq+1)+(Dq+1)-(CDq+1)
Q=size-Q
print(Q)












"""
listsize=B-A-1
Q=0
for i in range(listsize+1):
    number=i+A
    if number % C is not 0 and number % D is not 0:
        Q+=1
print(Q)
"""