input
stringlengths 20
127k
| target
stringlengths 20
119k
| problem_id
stringlengths 6
6
|
---|---|---|
T1, T2 = list(map(int, input().split()))
A1, A2 = list(map(int, input().split()))
B1, B2 = list(map(int, input().split()))
D1 = T1 * A1 - T1 * B1
D2 = T1 * A1 + T2 * A2 - T1 * B1 - T2 * B2
if D1 * D2 > 0:
print((0))
elif D2 == 0:
print("infinity")
else:
c = 1
D1 = abs(D2 - D1)
D2 = abs(D2)
Dp = D2
while True:
Dp += D2
if Dp > D1:
break
elif Dp == D1:
c += 1
break
c += 2
print(c)
|
T1, T2 = list(map(int, input().split()))
A1, A2 = list(map(int, input().split()))
B1, B2 = list(map(int, input().split()))
D1 = T1 * A1 - T1 * B1
D2 = T1 * A1 + T2 * A2 - T1 * B1 - T2 * B2
if D1 * D2 > 0:
print((0))
elif D2 == 0:
print("infinity")
else:
D1 = abs(D2 - D1)
D2 = abs(D2)
c = (D1 // D2) * 2 - 1
if D1 % D2 == 0:
c -= 1
print(c)
|
p02846
|
import sys
t1, t2 = list(map(int, input().split()))
a1, a2 = list(map(int, input().split()))
b1, b2 = list(map(int, input().split()))
if t1*a1+t2*a2 == t1*b1+t2*b2:
print("infinity")
sys.exit()
a, b = 0, 0
key = 0
ans = 0
while True:
key = ans
while True:
a_past, b_past = a, b
a += a1*t1
b += b1*t1
if a_past == b_past:
break
if (a_past-b_past)*(a-b) <= 0:
ans += 1
break
while True:
a_past, b_past = a, b
a += a2*t2
b += b2*t2
if a_past == b_past:
break
if (a_past-b_past)*(a-b) <= 0:
ans += 1
break
if key == ans:
break
print(ans)
|
import sys
t1, t2 = list(map(int, input().split()))
a1, a2 = list(map(int, input().split()))
b1, b2 = list(map(int, input().split()))
if (a1-b1)*t1+(a2-b2)*t2 == 0:
print("infinity")
sys.exit()
e1 = (a1-b1)*t1
e2 = e1 + (a2-b2)*t2
if e1*e2 > 0:
print((0))
sys.exit()
e1, e2 = abs(e1), abs(e2)
if e1%e2:
print((1+2*(e1//e2)))
else:
print((2*(e1//e2)))
|
p02846
|
T1, T2 = list(map(int, input().split()))
A1, A2 = list(map(int, input().split()))
B1, B2 = list(map(int, input().split()))
a = A1*T1-B1*T1
b = A2*T2-B2*T2
if a<0:
if b<0:
print((0))
elif b==0:
print((0))
elif b>0:
if a<-b:
print((0))
elif a==-b:
print('infinity')
else:
d = a+b
if a%d==0:
n = (-a)//d-1
print((2*n+2))
else:
n = (-a)//d
print((2*n+1))
elif a==0:
if b<0:
print((1))
elif b==0:
print('infinity')
elif b>0:
print((1))
elif a>0:
if b<0:
if a>-b:
print((0))
elif a==-b:
print('infinity')
else:
d = -a-b
if a%d==0:
n = a//d-1
print((2*n+2))
else:
n = a//d
print((2*n+1))
elif b==0:
print((0))
elif b>0:
print((0))
|
T1, T2 = list(map(int, input().split()))
A1, A2 = list(map(int, input().split()))
B1, B2 = list(map(int, input().split()))
d1 = (A1-B1)*T1
d2 = (A2-B2)*T2
if d1*d2>0:
print((0))
exit()
if d1<0:
d1 *= -1
d2 *= -1
if d1+d2>0:
print((0))
exit()
if d1+d2==0:
print('infinity')
exit()
t = -d2-d1
if d1%t==0:
print((d1//t*2))
else:
print((d1//t*2+1))
|
p02846
|
T1,T2 = list(map(int,input().split()))
A1,A2 = list(map(int,input().split()))
B1,B2 = list(map(int,input().split()))
C1 = (A1-B1)*T1
C2 = (A2-B2)*T2
if C1+C2==0:
print('infinity')
elif C1*(C1+C2)>0:
print((0))
else:
if abs(C1)%abs(C1+C2)==0:
print((abs(C1)//abs(C1+C2)*2))
else:
print((abs(C1)//abs(C1+C2)*2+1))
|
T1, T2 = list(map(int, input().split()))
A1, A2 = list(map(int, input().split()))
B1, B2 = list(map(int, input().split()))
C1 = A1 - B1
C2 = A2 - B2
if C1 * C2 >= 0:
print((0))
else:
if C1 < 0:
C1, C2 = -C1, -C2
P = T1 * C1
Q = P + T2 * C2
if Q > 0:
print((0))
elif Q == 0:
print('infinity')
else:
hi = 10**18
lo = -1
while hi - lo > 1:
mid = (hi + lo) // 2
if Q * mid + P <= 0:
hi = mid
else:
lo = mid
if Q * hi + P == 0:
print((hi * 2))
else:
print((hi * 2 - 1))
|
p02846
|
#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
t1,t2 = LI()
a1,a2 = LI()
b1,b2 = LI()
x,y = a1*t1,b1*t1
z,w = a1*t1 + a2*t2, b1*t1 + b2*t2
if (x > y and z > w) or (y > x and w > z):
print((0))
quit()
if (z == w) :
print('infinity')
quit()
if x < y:
x,y = y,x
if z < w:
z,w = w,z
s1 = x - y
s2 = z - w
p = math.ceil(s1/s2)
q = s1 % s2
ans = 2*p - (q != 0)
print(ans)
|
#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
t1, t2 = LI()
a1, a2 = LI()
b1, b2 = LI()
a = a1 * t1 + a2 * t2
b = b1 * t1 + b2 * t2
if a == b:
print('infinity')
else:
if b > a:
if a1 * t1 < b1 * t1:
print((0))
elif a1 * t1 == b1 * t1:
print((1))
elif a1 * t1 > b1 * t1:
c = b - a
d = a1 * t1 - b1 * t1
e = d % c != 0
print((2 * (d // c) + e))
else:
if b1 * t1 < a1 * t1:
print((0))
elif b1 * t1 == a1 * t1:
print((1))
elif b1 * t1 > a1 * t1:
c = a - b
d = b1 * t1 - a1 * t1
e = d % c != 0
print((2 * (d // c) + e))
|
p02846
|
T1,T2=list(map(int,input().split()))
A1,A2=list(map(int,input().split()))
B1,B2=list(map(int,input().split()))
if B1>A1:
A1,A2,B1,B2=B1,B2,A1,A2
if A2>B2:
print((0))
exit()
if A1*T1+A2*T2==B1*T1+B2*T2:
print("infinity")
exit()
ans=1
a,b=A1*T1+A2*T2,B1*T1+B2*T2
while b-a<=T1*A1-T1*B1:
if b-a<T1*A1-T1*B1:
ans+=2
else:
ans+=1
a+=A1*T1+A2*T2
b+=B1*T1+B2*T2
print(ans)
|
T1,T2=list(map(int,input().split()))
A1,A2=list(map(int,input().split()))
B1,B2=list(map(int,input().split()))
if B1>A1:
A1,A2,B1,B2=B1,B2,A1,A2
if A1*T1+A2*T2>B1*T1+B2*T2:
print((0))
exit()
if A1*T1+A2*T2==B1*T1+B2*T2:
print("infinity")
exit()
x=(T1*A1-T1*B1)//((B1-A1)*T1+(B2-A2)*T2)+1
ans=2*x-1
if (T1*A1-T1*B1)%((B1-A1)*T1+(B2-A2)*T2)==0:
ans-=1
print(ans)
|
p02846
|
import sys
sys.setrecursionlimit(1000000000)
from itertools import count
from functools import lru_cache
from collections import defaultdict
ii = lambda: int(eval(input()))
mis = lambda: list(map(int, input().split()))
lmis = lambda: list(mis())
INF = float('inf')
def meg(f, ok, ng):
while abs(ok-ng)>1:
mid = (ok+ng)//2
if f(mid):
ok=mid
else:
ng=mid
return ok
#
def main():
T1,T2 = mis()
A1,A2 = mis()
B1,B2 = mis()
d1 = T1*A1 - T1*B1
d2 = T2*A2 - T2*B2
if d1 + d2 == 0:
print('infinity')
elif d1 < 0 > d2 or d1 > 0 < d2:
print((0))
else:
ans = -1
pos = 0
if d1 < 0:
d1 *= -1
d2 *= -1
while True:
pos += d1
if pos == 0:
ans += 1
break
elif pos < 0:
break
else:
ans += 1
pos += d2
ans += 1
print(ans)
main()
|
import sys
sys.setrecursionlimit(1000000000)
from itertools import count
from functools import lru_cache
from collections import defaultdict
ii = lambda: int(eval(input()))
mis = lambda: list(map(int, input().split()))
lmis = lambda: list(mis())
INF = float('inf')
def meg(f, ok, ng):
while abs(ok-ng)>1:
mid = (ok+ng)//2
if f(mid):
ok=mid
else:
ng=mid
return ok
#
def main():
T1,T2 = mis()
A1,A2 = mis()
B1,B2 = mis()
d1 = T1*A1 - T1*B1
d2 = T2*A2 - T2*B2
if d1 + d2 == 0:
print('infinity')
elif d1 < 0 > d2 or d1 > 0 < d2:
print((0))
else:
if d1 < 0:
d1 *= -1
d2 *= -1
if d1 + d2 > 0:
print((0))
elif d1 % (d1+d2) == 0:
print((d1 // abs(d1+d2) * 2))
else:
print((d1 // abs(d1+d2) * 2 + 1))
main()
|
p02846
|
T1,T2 = list(map(int,input().split()))
A1,A2 = list(map(int,input().split()))
B1,B2 = list(map(int,input().split()))
dis1 = (A1 - B1) * T1
dis2 = (A2 - B2) * T2
if dis1 > 0:
dis1 = -dis1
dis2 = -dis2
if dis1 + dis2 <0:
print((0))
elif dis1 == -dis2:
print("infinity")
else:
S = dis1//(dis1+dis2)
R = dis1%(dis1+dis2)
if R == 0:
ans = S*2
else:
ans = S*2 + 1
print((abs(ans)))
|
T1,T2 = list(map(int,input().split()))
A1,A2 = list(map(int,input().split()))
B1,B2 = list(map(int,input().split()))
dis1 = (A1 - B1) * T1
dis2 = (A2 - B2) * T2
if dis1 > 0:
dis1 = -dis1
dis2 = -dis2
"""
if dis1 + dis2 <0:
print(0)
elif dis1 == -dis2:
print("infinity")
"""
if dis1 + dis2 == 0:
print("infinity")
elif dis1+dis2 < 0:
print((0))
else:
S = dis1//(dis1+dis2)
R = dis1%(dis1+dis2)
if R == 0:
ans = S*2
else:
ans = S*2 + 1
print((abs(ans)))
|
p02846
|
def sign(x):
if x==0:
return 0
else:
return abs(x)//x
def flag(x,y):
return sign(x)==sign(y)
T1,T2=list(map(int,input().split()))
A1,A2=list(map(int,input().split()))
B1,B2=list(map(int,input().split()))
if A1*T1+A2*T2==B1*T1+B2*T2:
print("infinity")
exit()
ans=0
X=(B1-A1)*T1
Y=(B2-A2)*T2
tmp=0
while(1):
if tmp==0:
tmp+=X
else:
if not(flag(tmp,tmp+X)):
ans+=1
tmp+=X
if tmp==0:
tmp+=Y
else:
if not(flag(tmp,tmp+Y)):
ans+=1
tmp+=Y
if flag(tmp,tmp+X) and flag(tmp+X,tmp+X+Y):
break
print(ans)
|
T1,T2=list(map(int,input().split()))
A1,A2=list(map(int,input().split()))
B1,B2=list(map(int,input().split()))
X=(B1-A1)*T1
Y=(B2-A2)*T2
if X>0:
X=-X
Y=-Y
if X+Y<0:
print((0))
elif X+Y==0:
print("infinity")
else:
A=(-X)//(X+Y)
B=(-X)%(X+Y)
if B!=0:
print((2*A+1))
else:
print((2*A))
|
p02846
|
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
t = LI()
a = LI()
b = LI()
a[0] -= b[0]
a[1] -= b[1]
if t[0]*a[0] == -t[1]*a[1]:
print("infinity")
return
if a[0] < 0:
a[0] *= -1
a[1] *= -1
if t[0]*a[0]+t[1]*a[1] > 0:
print((0))
return
l = 0
r = 10**100
A = t[0]*a[0]+t[1]*a[1]
while r-l > 1:
m = (l+r) >> 1
x = m*A
y = x+t[0]*a[0]
if x*y <= 0:
l = m
else:
r = m
ans = r*2-1
if l*A+t[0]*a[0] == 0:
ans -= 1
print(ans)
return
#Solve
if __name__ == "__main__":
solve()
|
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
t = LI()
a = LI()
b = LI()
a[0] -= b[0]
a[1] -= b[1]
if t[0]*a[0] == -t[1]*a[1]:
print("infinity")
return
if a[0] < 0:
a[0] *= -1
a[1] *= -1
if t[0]*a[0]+t[1]*a[1] > 0:
print((0))
return
A = t[0]*a[0]+t[1]*a[1]
k = t[0]*a[0]
x = k//(-A)
ans = 2*x+1
if A*x+k == 0:
ans -= 1
print(ans)
return
#Solve
if __name__ == "__main__":
solve()
|
p02846
|
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def ceil(a, b):
return (a + b - 1) // b
def sum_of_arithmetic_progression(s, d, n):
return n * (2 * s + (n - 1) * d) // 2
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def lcm(a, b):
g = gcd(a, b)
return a / g * b
def meet(diff, T1, T2, A1, A2, B1, B2):
ans = 0
pre_diff = diff
a = T1 * A1
b = T1 * B1
diff += a
diff -= b
if (pre_diff * diff) < 0 or (pre_diff != 0 and diff == 0):
ans += 1
pre_diff = diff
a = T2 * A2
b = T2 * B2
diff += a
diff -= b
if (pre_diff * diff) < 0 or (pre_diff != 0 and diff == 0):
ans += 1
return ans
def solve():
T1, T2 = list(map(int, input().split()))
A1, A2 = list(map(int, input().split()))
B1, B2 = list(map(int, input().split()))
# 無限回
if (T1 * A1 + T2 * A2) == (T1 * B1 + T2 * B2):
print("infinity")
return
# 0回
if (A1 > B1 and A2 > B2) or (A1 < B1 and A2 < B2):
print((0))
return
one_diff = (T1 * A1 + T2 * A2) - (T1 * B1 + T2 * B2)
ans = 0
diff = 0
while True:
num = meet(diff, T1, T2, A1, A2, B1, B2)
if num == 0:
break
ans += num
diff += one_diff
print(ans)
def main():
solve()
if __name__ == '__main__':
main()
|
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def ceil(a, b):
return (a + b - 1) // b
def sum_of_arithmetic_progression(s, d, n):
return n * (2 * s + (n - 1) * d) // 2
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def lcm(a, b):
g = gcd(a, b)
return a / g * b
def meet(diff, T1, T2, A1, A2, B1, B2):
ans = 0
pre_diff = diff
a = T1 * A1
b = T1 * B1
diff += a
diff -= b
if (pre_diff * diff) < 0 or (pre_diff != 0 and diff == 0):
ans += 1
pre_diff = diff
a = T2 * A2
b = T2 * B2
diff += a
diff -= b
if (pre_diff * diff) < 0 or (pre_diff != 0 and diff == 0):
ans += 1
return ans
def solve():
T1, T2 = list(map(int, input().split()))
A1, A2 = list(map(int, input().split()))
B1, B2 = list(map(int, input().split()))
# 無限回
if (T1 * A1 + T2 * A2) == (T1 * B1 + T2 * B2):
print("infinity")
return
# 0回
if (A1 > B1 and A2 > B2) or (A1 < B1 and A2 < B2):
print((0))
return
one_diff = (T1 * A1 + T2 * A2) - (T1 * B1 + T2 * B2)
ans = 0
diff = 0
for i in range(100):
num = meet(diff, T1, T2, A1, A2, B1, B2)
if num == 0:
break
ans += num
diff += one_diff
left = -1
right = 10**20
while right - left > 1:
m = (right + left) // 2
tmp = diff + m * one_diff
if meet(tmp, T1, T2, A1, A2, B1, B2):
left = m
else:
right = m
x = max(0, left - 10)
ans += meet(diff, T1, T2, A1, A2, B1, B2) * x
diff += one_diff * x
for i in range(100):
num = meet(diff, T1, T2, A1, A2, B1, B2)
if num == 0:
break
ans += num
diff += one_diff
print(ans)
def main():
solve()
if __name__ == '__main__':
main()
|
p02846
|
T1,T2 = list(map(int,input().split()))
A1,A2 = list(map(int,input().split()))
B1,B2 = list(map(int,input().split()))
dif = T1*A1+T2*A2-T1*B1-T2*B2
if dif==0:
print("infinity")
elif dif>0:
if B1>A1:
k = int(((B1-A1)*T1)/dif)
if abs(((B1-A1)*T1)/dif-round(((B1-A1)*T1)/dif))<1e-20:
print((2*round(((B1-A1)*T1)/dif)))
else:
print((2*k+1))
else:
print((0))
else:
if A1>B1:
k = int(((A1-B1)*T1)/abs(dif))
if abs((A1-B1)*T1/abs(dif)-round(((A1-B1)*T1)/abs(dif)))<1e-20:
print((2*round(((A1-B1)*T1)/abs(dif))))
else:
print((2*k+1))
else:
print((0))
|
T1,T2 = list(map(int,input().split()))
A1,A2 = list(map(int,input().split()))
B1,B2 = list(map(int,input().split()))
if T1*A1+T2*A2==T1*B1+T2*B2:
cnt="infinity"
elif T1*A1+T2*A2>T1*B1+T2*B2:
L = T1*(B1-A1)
d = T1*A1+T2*A2-(T1*B1+T2*B2)
if L<0:
cnt = 0
elif L==0:
cnt = 1
else:
cnt = 1
n = L//d
r = L%d
if r>0:
cnt += 2*n
else:
cnt += 2*(n-1)+1
elif T1*A1+T2*A2<T1*B1+T2*B2:
L = T1*(A1-B1)
d = (T1*B1+T2*B2)-(T1*A1+T2*A2)
if L<0:
cnt = 0
elif L==0:
cnt = 1
else:
cnt = 1
n = L//d
r = L%d
if r>0:
cnt += 2*n
else:
cnt += 2*(n-1)+1
print(cnt)
|
p02846
|
T1,T2 = list(map(int,input().split()))
A1,A2 = list(map(int,input().split()))
B1,B2 = list(map(int,input().split()))
len1 = T1 * A1 + T2 * A2
len2 = T1 * B1 + T2 * B2
if len1 == len2:
print("infinity")
quit()
ans = 0
subs = 0
sub1 = T1 * (A1 - B1)
sub2 = T2 * (A2 - B2)
X = [1, 1]
i = 0
while (X != [0, 0]):
i += 1
if subs != 0:
if subs ** 2 + subs * sub1 <= 0:
ans += 1
X[0] = 1
else:
X[0] = 0
subs = subs + sub1
if subs != 0:
if subs ** 2 + subs * sub2 <= 0:
ans += 1
X[1] = 1
else:
X[1] = 0
subs = subs + sub2
print(ans)
|
T1,T2 = list(map(int,input().split()))
A1,A2 = list(map(int,input().split()))
B1,B2 = list(map(int,input().split()))
len1 = T1 * A1 + T2 * A2
len2 = T1 * B1 + T2 * B2
if len1 == len2:
print("infinity")
quit()
ans = 0
subs = 0
sub1 = T1 * (A1 - B1)
sub2 = T2 * (A2 - B2)
if sub1 > 0:
if len1 - len2 > 0:
ans = 0
else:
S = (-1 * sub1) // (sub1 + sub2)
T = (-1 * sub1) % (sub1 + sub2)
if T == 0:
ans = 2 * S
else:
ans = 2 * S + 1
else:
if len1 - len2 < 0:
ans = 0
else:
S = (-1 * sub1) // (sub1 + sub2)
T = (-1 * sub1) % (sub1 + sub2)
if T == 0:
ans = 2 * S
else:
ans = 2 * S + 1
print(ans)
|
p02846
|
T1, T2 = list(map(int, input().split()))
A1, A2 = list(map(int, input().split()))
B1, B2 = list(map(int, input().split()))
D1 = T1 * (A1 - B1)
D2 = T2 * (A2 - B2)
li = [D1, D2]
li.sort()
pos = 0
cnt = 0
for _ in range(10000000):
pos += li[0]
pos1 = pos
pos += li[1]
pos2 = pos
if pos1 < 0 and pos2 >= 0:
cnt += 2
if cnt >= 1000000:
print("infinity")
else:
print((cnt-1))
|
t1, t2 = list(map(int, input().split()))
a1, a2 = list(map(int, input().split()))
b1, b2 = list(map(int, input().split()))
if ((a1 - b1) * (a2 - b2) > 0) or (abs(a1 - b1) * t1 > abs(a2 - b2) * t2):
print((0))
elif abs(a1 - b1) * t1 == abs(a2 - b2) * t2:
print("infinity")
else:
d, m = divmod(abs(a1 - b1) * t1, abs(a2 - b2) * t2 - abs(a1 - b1) * t1)
ans = d * 2
if m > 0:
ans += 1
print(ans)
|
p02846
|
T1,T2 = list(map(int,input().split()))
A1,A2 = list(map(int,input().split())) #高橋君
B1,B2 = list(map(int,input().split())) #青木君
# 時間配列
T = [T1]
f = 1
for i in range(3):
if f:
Tn = T2
f = 0
else:
Tn = T1
f = 1
T.append(T[-1]+Tn)
# print(T)
class runner():
def __init__(self,v1,v2):
self.v1 = v1
self.v2 = v2
def distance(self,t):
d = t//(T1+T2)*(self.v1*T1 + self.v2*T2)
tm = t % (T1+T2)
# print("d",d,"tm",tm)
if tm < T1:
d += self.v1 * tm
else:
d += self.v2*(tm-T1) + self.v1*T1
return d
dif = runner(A1-B1,A2-B2)
c = -1
D = 0
DL = [0]
for t in T:
pD = D
D = dif.distance(t)
DL.append(D)
# print(D)
if pD*D <= 0:
c += 1
# print(c)
# print(DL)
if DL[1]*DL[2] > 0:
print((0))
else:
if DL[2] == 0:
print("infinity")
else:
a = DL[2]
if a>0:
if -DL[1]%a == 0:
print((-DL[1]//a*2))
else:
print((-DL[1]//a*2+1))
else:
if -DL[1]%a == 0:
print((-DL[1]//a*2))
else:
print((-DL[1]//a*2+1))
|
T1,T2 = list(map(int,input().split()))
A1,A2 = list(map(int,input().split())) #高橋君
B1,B2 = list(map(int,input().split())) #青木君
D1,D2 = (A1-B1)*T1, (A1-B1)*T1+(A2-B2)*T2
if D1*D2 > 0:
print((0))
elif D2 == 0:
print("infinity")
else:
if -D1%D2 == 0:
print((-D1//D2*2))
else:
print((-D1//D2*2+1))
|
p02846
|
t,T,a,A,b,B=list(map(int, open(0).read().split()))
x,y=(a-b)*t,(A-B)*T
if x+y==0:
r="infinity"
else:
s,t=divmod(-x, x+y)
r=0 if s<0 else s*2+(1 if t else 0)
print(r)
|
t,T,a,A,b,B=list(map(int, open(0).read().split()))
x,y=(b-a)*t,(A-B)*T
if y-x==0:
r="infinity"
else:
s,t=divmod(x,y-x)
r=max(0,s*2+(1 if t else 0))
print(r)
|
p02846
|
def gcd(a, b):
if a < b:
a, b = b, a
if b == 0:
return a
c = a % b
return int(gcd(b, c))
def lcm(a, b):
return int(a * b / gcd(a,b))
A, B, C, D = [int(x) for x in input().split()]
l = lcm(C, D)
A = A-1
x = (B-A)
y = (B//C - A//C)
z = (B//D - A//D)
a = (B//l - A//l)
print((x+a - (y+z)))
|
def gcd(a, b):
if a < b:
a, b = b, a
if b == 0:
return a
r = a % b
return gcd(b, r)
def lcm(a, b):
return a*b // gcd(a, b)
A, B, C, D = list(map(int, input().split()))
l = lcm(C, D)
A = A-1
N_range = B - A
l_sum = (B//l) - (A//l)
c_sum = (B//C) - (A//C)
d_sum = (B//D) - (A//D)
print((N_range - c_sum - d_sum + l_sum))
|
p02995
|
# -*-coding: utf-8 -*-
import sys
import math
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def lcm(x, y):
return (x * y) // gcd(x, y)
def main():
input = sys.stdin.readline
a, b, c, d = list(map(int, input().split()))
a_1 = a - 1
lcm_cd = lcm(c,d)
a_1_c_count = a_1 // c
a_1_d_count = a_1 // d
a_lcm_count = a_1 // lcm_cd
a_1_result = a_1 - (a_1_c_count + a_1_d_count - a_lcm_count)
b_c_count = b // c
b_d_count = b // d
b_lcm_count = b // lcm_cd
b_result = (b) - (b_c_count + b_d_count - b_lcm_count)
result = b_result - a_1_result
print(result)
return
if __name__ == '__main__':
main()
|
import sys
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))
input = sys.stdin.readline
a, b, c, d = list(map(int, input().split()))
div_ac = (a-1) // c
div_bc = b // c
div_ad = (a-1) // d
div_bd = b // d
lcm_cd = lcm(c,d)
div_acd = (a-1) // lcm_cd
div_bcd = b // lcm_cd
a_1_result = div_ac + div_ad - div_acd
b_result = div_bc + div_bd - div_bcd
print(((b+1 - a) - (b_result - a_1_result)))
|
p02995
|
from math import *
a,b,c,d = list(map(int,input().split()))
f =(c*d)//gcd(c,d)
r = f
rock = 2
compteur= 0
if f<=b:
while f<=b:
if f>=a and f<=b:
compteur +=1
f = r*rock
rock += 1
div1 = ((b//c)-(a//c))
div2 = ((b//d)-(a//d))
if a%c == 0:
div1+=1
if a%d ==0:
div2 +=1
roger =(div1+div2)-compteur
mm = (b-a)+1
print((mm-roger))
|
from math import *
a,b,c,d = list(map(int,input().split()))
f =(c*d)//gcd(c,d)
r = f
rock = 2
compteur= (b//f)-(a//f)
if a%f==0:
compteur +=1
div1 = ((b//c)-(a//c))
div2 = ((b//d)-(a//d))
if a%c == 0:
div1+=1
if a%d ==0:
div2 +=1
roger =(div1+div2)-compteur
mm = (b-a)+1
print((mm-roger))
|
p02995
|
import sys
def S(): return sys.stdin.readline().rstrip()
A,B,C,D = list(map(int,S().split()))
from math import gcd
def f(n): # 1からnまでCでもDでも割り切れない自然数の個数
return n-n//C-n//D+n//(C*D//gcd(C,D))
print((f(B)-f(A-1)))
|
import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
A,B,C,D = MI()
from math import gcd
def f(n):
return n-n//C-n//D+n//((C*D)//gcd(C,D))
print((f(B)-f(A-1)))
|
p02995
|
import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
A,B,C,D = MI()
from math import gcd
def f(n):
return n-n//C-n//D+n//((C*D)//gcd(C,D))
print((f(B)-f(A-1)))
|
import sys
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
A,B,C,D = MI()
from math import gcd
def f(n):
return n-n//C-n//D+n//((C*D)//gcd(C,D))
print((f(B)-f(A-1)))
|
p02995
|
import math
A, B, C, D = list(map(int, input().split()))
def lcm(x, y):
return (x * y) // math.gcd(x, y)
X = lcm(C, D)
ansB = (B-B//C)+(B-B//D)-(B-B//X)
ansA = ((A-1)-((A-1)//C))+((A-1)-(A-1)//D)-((A-1)-(A-1)//X)
print((ansB-ansA))
|
import math
A, B, C, D = list(map(int, input().split()))
X= (C * D) // math.gcd(C, D)
ansB = (B-B//C)+(B-B//D)-(B-B//X)
ansA = ((A-1)-((A-1)//C))+((A-1)-(A-1)//D)-((A-1)-(A-1)//X)
print((ansB-ansA))
|
p02995
|
#!/usr/bin/env python3
#ABC131 C
import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def gcd(n,m):
if m == 0:
return n
else:
return gcd(m,n%m)
def lcm(n,m):
return (n*m)//gcd(n,m)
a,b,c,d = LI()
i,j,k = (a-1)//c,(a-1)//d,(a-1)//lcm(c,d)
s,t,u = b//c,b//d,b//lcm(c,d)
x = b - s - t + u
y = (a-1) - i - j + k
print((x -y))
|
#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
a, b, c, d = LI()
ans = b - a + 1
lcm = c * d // math.gcd(c, d)
ans -= b // c - ((a-1) // c + 1) + 1
ans -= b // d - ((a-1) // d + 1) + 1
ans += b // lcm - ((a-1) // lcm + 1) + 1
print(ans)
|
p02995
|
# -*- coding: utf-8 -*-
'''Snippets for lcm.
Available functions:
- lcm: Compute least common multiple of a and b.
'''
def lcm(a: int, b: int) -> int:
'''Compute least common multiple of a and b.
Args:
a: Int of number (greater than 0).
b: Int of number (greater than 0).
Returns:
least common multiple.
Landau notation: O(log n)
See:
https://gist.github.com/endolith/114336/eff2dc13535f139d0d6a2db68597fad2826b53c3
https://docs.python.org/3/library/sys.html#sys.version_info
'''
from sys import version_info
if version_info.major == 3 and version_info.minor >= 5:
from math import gcd
else:
from fractions import gcd
return a * b // gcd(a, b)
def main():
a, b, c, d = list(map(int, input().split()))
l = lcm(c, d)
x = b // c - (a - 1) // c
y = b // d - (a - 1) // d
z = b // l - (a - 1) // l
w = b - a + 1
if c % d == 0 or d % c == 0:
print((w - x))
else:
print((w - (x + y - z)))
if __name__ == '__main__':
main()
|
# -*- coding: utf-8 -*-
'''Snippets for lcm.
Available functions:
- lcm: Compute least common multiple of a and b.
'''
def lcm(a: int, b: int) -> int:
'''Compute least common multiple of a and b.
Args:
a: Int of number (greater than 0).
b: Int of number (greater than 0).
Returns:
least common multiple.
Landau notation: O(log n)
See:
https://gist.github.com/endolith/114336/eff2dc13535f139d0d6a2db68597fad2826b53c3
https://docs.python.org/3/library/sys.html#sys.version_info
'''
from sys import version_info
if version_info.major == 3 and version_info.minor >= 5:
from math import gcd
else:
from fractions import gcd
return a * b // gcd(a, b)
def main():
a, b, c, d = list(map(int, input().split()))
l = lcm(c, d)
x = b // c - (a - 1) // c
y = b // d - (a - 1) // d
z = b // l - (a - 1) // l
w = b - a + 1
print((w - (x + y - z)))
if __name__ == '__main__':
main()
|
p02995
|
a,b,c,d = list(map(int,input().split()))
def gcd(x,y):
while y>0:
x,y = y,x%y
return x
def lcm(x,y):
return x*y//gcd(x,y)
ans = (b-a+1) - (b//c-a//c)- (b//d-a//d) + b//lcm(d,c) - a//lcm(d,c)
if a%c == 0 and a%d != 0:
ans -=1
elif a%c != 0 and a%d == 0:
ans -=1
elif a%c == 0 and a%d == 0:
ans -=1
print(ans)
|
a,b,c,d = list(map(int,input().split()))
def gcd(x,y):
while y>0:
x,y = y,x%y
return x
def lcm(x,y):
return x*y//gcd(x,y)
ans = (b-a+1) - (b//c-(a-1)//c)- (b//d-(a-1)//d) + b//lcm(d,c) - (a-1)//lcm(d,c)
print(ans)
|
p02995
|
import sys
import math
input = sys.stdin.readline# 最小公倍数
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()))
e = lcm(c, d)
#print("e: {}".format(e))
#print("c: {} - {}".format(b // c, (a - 1) // c))
#print("d: {} - {}".format(b // d, (a - 1) // d))
#print("e: {} - {}".format(b // e, (a - 1) // e))
count_c = b // c - (a - 1) // c
count_d = b // d - (a - 1) // d
count_e = b // e - (a - 1) // e
# b - a の中から d の倍数の個数を取得
#print("count_c: {}".format(count_c))
#print("count_d: {}".format(count_d))
#print("count_e: {}".format(count_e))
print((b - a + 1 - (count_c + count_d - count_e)))
|
import sys
input = sys.stdin.readline# 最小公倍数
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()))
e = lcm(c, d)
count_c = b // c - (a - 1) // c
count_d = b // d - (a - 1) // d
count_e = b // e - (a - 1) // e
print((b - a + 1 - (count_c + count_d - count_e)))
|
p02995
|
def gcd(x,y):
x, y = max(x,y), min(x,y)
while x!=y :
x, y = max(x,y), min(x,y)
x -= y
return x
#print(gcd(4,8))
a,b,c,d = list(map(int,input().split()))
c_ok = b//c - (a-1)//c
d_ok = b//d - (a-1)//d
cd = int(c*d/gcd(c,d))
cd_ok = b//cd - (a-1)//cd
print((int(b-a+1-c_ok-d_ok+cd_ok)))
|
def gcd(x,y):
x, y = max(x,y), min(x,y)
while x!=0 :
x, y = max(x,y), min(x,y)
x %= y
return y
#print(gcd(4,8))
a,b,c,d = list(map(int,input().split()))
c_ok = b//c - (a-1)//c
d_ok = b//d - (a-1)//d
cd = int(c*d/gcd(c,d))
cd_ok = b//cd - (a-1)//cd
print((int(b-a+1-c_ok-d_ok+cd_ok)))
|
p02995
|
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a%b)
A, B, C, D = list(map(int, input().split()))
CD = C*D//gcd(C, D)
count1 = (B // C - A // C)
count2 = (B // D - A // D)
count3 = (B // CD - A // CD)
if A % C == 0:
count1 += 1
if A % D == 0:
count2 += 1
if A % CD == 0:
count3 += 1
print((B - A + 1 - ((count1 + count2) - count3)))
|
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a%b)
A, B, C, D = list(map(int, input().split()))
CD = C*D//gcd(C, D)
count1 = (B // C - (A - 1) // C)
count2 = (B // D - (A - 1) // D)
count3 = (B // CD - (A - 1) // CD)
print((B - (A - 1) - ((count1 + count2) - count3)))
|
p02995
|
def gcd(i,j):
if i > j:
tmp = i
i = j
j = tmp
while i != 0:
tmp = i
i = j%i
j = tmp
return j
def lcm(i,j):
return i*j//gcd(i,j)
def main():
a,b,c,d = list(map(int,input().split()))
ans = b-a+1
ans -= (b//c - (a-1)//c) + (b//d - (a-1)//d) - (b//lcm(c,d) -(a-1)//lcm(c,d))
print(ans)
main()
|
#!/usr/bin/env python3
a,b,c,d = list(map(int,input().split()))
def my_gcd(i,j):
if i > j: i,j = j,i
while i != 0:
if j % i != 0:
i,j = j%i,i
else: return i
def not_div(n):
return b//n - (a-1) //n
print((not_div(1)-not_div(c)-not_div(d)+not_div(c*d//my_gcd(c,d))))
|
p02995
|
from math import floor, ceil, gcd
a,b,c,d = list(map(int, input().split()))
if a%c == 0: c_m_min = a
else: c_m_min = a + c - a%c
c_m_max = b - b%c
c_cnt = (c_m_max - c_m_min)//c + 1
if c_m_min > b or c_m_max < a : c_cnt = 0
if a%d == 0: d_m_min = a
else: d_m_min = a + d - a%d
d_m_max = b - b%d
d_cnt = (d_m_max - d_m_min)//d + 1
if d_m_min > b or d_m_max < a : d_cnt = 0
cd = c*d//gcd(c,d)
if a%cd == 0: cd_m_min = a
else: cd_m_min = a + cd - a%cd
cd_m_max = b - b%cd
cd_cnt = (cd_m_max - cd_m_min)//cd + 1
if cd_m_min > b or cd_m_max < a : cd_cnt = 0
ans = b - a + 1 - c_cnt - d_cnt + cd_cnt
print(ans)
|
from math import gcd
def lcm(x,y):
return (x * y) // gcd(x, y)
a,b,c,d = list(map(int, input().split()))
a_cnt = 0
a_cnt = (b//c) - ((a-1)//c)
b_cnt = (b//d) - ((a-1)//d)
lcmab = lcm(c,d)
ab_cnt = (b//lcmab) - ((a-1)//lcmab)
ans = (b-a+1) - a_cnt -b_cnt + ab_cnt
print(ans)
|
p02995
|
#@k0gane_p
a, b, c, d = [int(i) for i in input().split()]
def gcd(x,y):#最大公約数
while y:
x,y = y, x%y
return x
def lcm(x,y):#最小公倍数
return x*y // gcd (x,y)
def count(A,B,C):#A以下で、BでもCでも割り切れない個数
D=A//B
E=A//C
F=A // lcm(B,C)
return A-D-E+F
ans = count(b, c, d) - count(a, c, d)
#A以上B以下の整数のうち、CでもDでも割り切れないものの個数
if(a % c != 0 and a % d != 0):
ans += 1#AがCでもDでも割り切れないなら、足す1
print(ans)
|
#@k0gane_p
a, b, c, d = [int(i) for i in input().split()]
def gcd(x,y):#最大公約数
while y:
x,y = y, x%y
return x
def lcm(x,y):#最小公倍数
return x*y // gcd (x,y)
def count(A,B,C):#A以下で、BでもCでも割り切れない個数
D=A//B
E=A//C
F=A // lcm(B,C)
return A-D-E+F
ans = count(b, c, d) - count(a-1, c, d)
#A以上B以下の整数のうち、CでもDでも割り切れないものの個数
#if(a % c != 0 and a % d != 0):
#ans += 1#AがCでもDでも割り切れないなら、足す1
print(ans)
|
p02995
|
#@k0gane_p
a, b, c, d = [int(i) for i in input().split()]
def gcd(x,y):#最大公約数
while y:
x,y = y, x%y
return x
def lcm(x,y):#最小公倍数
return x*y // gcd (x,y)
def count(A,B,C):#A以下で、BでもCでも割り切れない個数
D=A//B
E=A//C
F=A // lcm(B,C)
return A-D-E+F
ans = count(b, c, d) - count(a-1, c, d)
#A以上B以下の整数のうち、CでもDでも割り切れないものの個数
#if(a % c != 0 and a % d != 0):
#ans += 1#AがCでもDでも割り切れないなら、足す1
print(ans)
|
#@k0gane_p
a, b, c, d = [int(i) for i in input().split()]
def gcd(x,y):#最大公約数
while y:
x,y = y, x%y
return x
def lcm(x,y):#最小公倍数
return x*y // gcd (x,y)
def count(A,B,C):#A以下で、BでもCでも割り切れない個数
D=A//B
E=A//C
F=A // lcm(B,C)#Fは両方で割り切れる、最小公倍数で割り切れる
return A-D-E+F#包除原理
ans = count(b, c, d) - count(a-1, c, d)
#A以上B以下の整数のうち、CでもDでも割り切れないものの個数
#Aを引く1することで、A以上が分かる
#if(a % c != 0 and a % d != 0):
#ans += 1#AがCでもDでも割り切れないなら、足す1
print(ans)
|
p02995
|
#!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce
def input():
return sys.stdin.readline()[:-1]
def sort_zip(a:list, b:list):
z = list(zip(a, b))
z = sorted(z)
a, b = list(zip(*z))
a = list(a)
b = list(b)
return a, b
def warikirenai(n, warukazu):
return n - n // warukazu
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
def lcm(*numbers):
return reduce(lcm_base, numbers, 1)
def main():
A, B, C, D = list(map(int, input().split()))
ansA = 0
ansA += warikirenai(A - 1, C)
ansA += warikirenai(A - 1, D)
ansA -= warikirenai(A - 1, lcm(C, D))
ansB = 0
ansB += warikirenai(B, C)
ansB += warikirenai(B, D)
ansB -= warikirenai(B, lcm(C, D))
print((ansB - ansA))
if __name__ == '__main__':
main()
|
#!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce
def input():
return sys.stdin.readline()[:-1]
def sort_zip(a:list, b:list):
z = list(zip(a, b))
z = sorted(z)
a, b = list(zip(*z))
a = list(a)
b = list(b)
return a, b
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
def lcm(*numbers):
return reduce(lcm_base, numbers, 1)
def warikirenai(n, c, d):
num = n - n // c
num += n - n // d
num -= n - n // lcm(c, d)
return num
def main():
A, B, C, D = list(map(int, input().split()))
print((warikirenai(B, C, D) - warikirenai(A - 1, C, D)))
if __name__ == '__main__':
main()
|
p02995
|
import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
from pprint import pprint
sys.setrecursionlimit(1000000)
# MOD = 10 ** 9 + 7
# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
A, B, C, D = [int(x) for x in input().split()]
def gcd(x, y):
while (y):
x, y = y, x % y
return x
def lcm(x, y):
return (x * y) // gcd(x, y)
def f(a, b, c):
if a % c == 0:
a1 = a // c
else:
a1 = a // c + 1
b1 = b // c
r = b1 - a1 + 1
return r
# c = (B - A + 1) // C
# d = (B - A + 1) // D
# cd = (B - A + 1) // (C * D)
c = f(A, B, C)
d = f(A, B, D)
cd = f(A, B, lcm(C, D))
n = B - A + 1
print((n - c - d + cd))
|
import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
from pprint import pprint
sys.setrecursionlimit(1000000)
# MOD = 10 ** 9 + 7
# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
A, B, C, D = [int(x) for x in input().split()]
def gcb(a, b):
# a, b = max([a, b]), min([a, b])
return a if b == 0 else gcb(b, a % b)
def lcm(a, b):
return a * b // gcb(a, b)
g = lcm(C, D)
c = B // C - (A - 1) // C
d = B // D - (A - 1) // D
cd = B // g - (A - 1) // g
print((B - A + 1 - c - d + cd))
|
p02995
|
import sys
from math import pi
def gcd(a, b):
a, b = max(a, b), min(a, b)
while a % b > 0:
a, b = b, a % b
return b
def solve():
input = sys.stdin.readline
A, B, C, D = list(map(int, input().split()))
cDiv = (B // C) - ((A - 1) // C)
dDiv = (B // D) - ((A - 1) // D)
cd = C * D // gcd(C, D)
cdDiv = (B // cd) - ((A - 1) // cd)
print(((B - A + 1) - (cDiv + dDiv - cdDiv)))
return 0
if __name__ == "__main__":
solve()
|
import sys
def lcm(a, b):
a, b = max(a, b), min(a, b)
c = a * b
while a % b > 0:
a, b = b, a % b
return c // b
def solve():
input = sys.stdin.readline
A, B, C, D = list(map(int, input().split()))
divC = B // C - (A - 1) // C
divD = B // D - (A - 1) // D
cd = lcm(C, D)
divCD = B // cd - (A - 1) // cd
print((B - A + 1 - (divC + divD - divCD)))
return 0
if __name__ == "__main__":
solve()
|
p02995
|
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=list(map(int,input().split()))
a-=1
b_1=b//c
b_1+=b//d
b_1-=b//lcm(c,d)
a_1=a//c
a_1+=a//d
a_1-=a//lcm(c,d)
print(((b-b_1)-(a-a_1)))
|
a,b,c,d=list(map(int,input().split()))
def gcd(a, b):
while b:
a, b = b, a % b
return a
#a,bの最小公倍数
def lcm(a, b):
return a * b // gcd (a, b)
a1=(a-1)//c
a2=b//c
b1=(a-1)//d
b2=b//d
new_lcm=lcm(c,d)
c1=(a-1)//new_lcm
c2=b//new_lcm
print(((b-a)+1-((a2-a1)+(b2-b1))+(c2-c1)))
#print(a1,a2,b1,b2,c1,c2)
|
p02995
|
A,B,C,D =list(map(int,input().split()))
x = C
y = D
while y>0:
x,y = y,x%y
E = (C//x)*D
bc = B//C
bd = B//D
be = B//E
b = B-(bc+bd-be)
ac = (A-1)//C
ad = (A-1)//D
ae = (A-1)//E
a = A-1-(ac+ad-ae)
print((b-a))
|
def gcd(x,y):
while y>0:
x,y = y,x%y
return x
A,B,C,D = list(map(int,input().split()))
c1 = B//C-(A-1)//C
d1 = B//D-(A-1)//D
E = (C//gcd(C,D))*D
e1 = B//E-(A-1)//E
print((B-A+1-c1-d1+e1))
|
p02995
|
from math import gcd
from decimal import Decimal as dec
a, b, c, d = list(map(dec,input().split()))
if a % c ==0:
c_explicit = b // c - a // c + 1
else:
c_explicit = b // c - a // c
if a % d ==0:
d_explicit = b // d - a // d + 1
else:
d_explicit = b // d - a // d
e = gcd(int(c), int(d))
e = dec(e)
gcl = (c / e) * (d / e) * e
if a % gcl ==0:
e_explicit = b // gcl - a // gcl + 1
else:
e_explicit = b // gcl - a // gcl
g = b - a + 1 - c_explicit - d_explicit + e_explicit
print(g)
|
from math import gcd as gcd
a, b, c, d = list(map(int,input().split()))
#cでわれるもの
s = gcd(c, d)
p = c * d // s
divide_c = b // c - (a - 1) // c
divide_d = b // d - (a - 1) // d
divide_cd = b // p - (a - 1) // p
print((int(b - a + 1 - divide_c - divide_d + divide_cd)))
|
p02995
|
import math
a, b, c, d = list(map(int, input().split()))
c_f = (a + c - 1) // c
c_e = b // c
d_f = (a + d - 1) // d
d_e = b // d
cd = c * d // math.gcd(c, d)
c_d_num = b // cd - (a + cd - 1) // cd + 1
num = b - a + 1 - (c_e - c_f + 1 + d_e - d_f + 1 - c_d_num)
print(num)
|
import math
a, b, c, d = list(map(int, input().split()))
def f(a, b, c):
return b // c - (a + c - 1) // c + 1
c_num = f(a, b, c)
d_num = f(a, b, d)
cp = c
dp = d
mod = 1
while mod > 0:
mod = cp % dp
cp = dp
dp = mod
cd_num = f(a, b, (c * d) // cp)
print((b - a + 1 - c_num - d_num + cd_num))
|
p02995
|
import math
from decimal import *
getcontext().prec = 50
a,b,c,d = list(map(int,input().split()))
from functools import reduce
def gcd(a,b):
if a < b:
a, b = b, a
while a % b != 0:
a, b = b, a % b
return b
def lcm_base(x, y):
return (x * y) // gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
gcd = lcm_list([c,d])
def solve(n):
start = n * math.ceil(Decimal(a) / Decimal(n))
end = n * (Decimal(b) // Decimal(n))
#print(start,end)
return (end - start) // n + 1
#print(solve(c),solve(d),solve(gcd))
ans = solve(c) + solve(d) - solve(gcd)
#print(ans)
print((b - a - ans + 1))
|
from functools import reduce
def gcd(a,b):
if a < b:
a, b = b, a
while a % b != 0:
a, b = b, a % b
return b
def lcm_base(x, y):
return (x * y) // gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
a,b,c,d = list(map(int,input().split()))
lcm = lcm_list([c,d])
res1 = a - 1 - ((a - 1) // c + (a - 1) // d - (a - 1) // lcm)
res2 = b - (b // c + b // d - b // lcm)
print((res2 - res1))
|
p02995
|
a, b, c, d = list(map(int, input().split()))
def gcd(a, b):
if a == 0:
return b
return gcd(b % a, a)
def count(x, y):
return x // y
cd = c * d // gcd(c, d)
print((b - a + 1 - count(b, c) + count(a - 1, c) - count(b, d) + count(a - 1, d) + count(b, cd) - count(a - 1, cd)))
|
a, b, c, d = list(map(int, input().split()))
def gcd(a, b):
return b if a == 0 else gcd(b % a, a)
def lcm(a, b):
return a // gcd(a, b) * b
def count(x):
return x - (x // c) - (x // d) + (x // lcm(c, d))
print((count(b) - count(a - 1)))
|
p02995
|
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=list(map(int,input().split()))
e=lcm(c,d)
cc=(b//c)-((a-1)//c)
dd=(b//d)-((a-1)//d)
cd=(b//e)-((a-1)//e)
print(((b-a+1)-(cc+dd-cd)))
|
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=list(map(int,input().split()))
e=lcm(c,d)
print(((b-a+1)-(b//c-(a-1)//c)-(b//d-(a-1)//d)+(b//e-(a-1)//e)))
|
p02995
|
from math import gcd
def count_indivs(N):
return N - (N // C + N // D - N // L)
A, B, C, D = list(map(int, input().split()))
L = C * D // gcd(C, D)
print((count_indivs(B) - count_indivs(A - 1)))
|
from math import gcd
def f(x):
return x - (x // C + x // D - x // lcm)
A, B, C, D = list(map(int, input().split()))
lcm = C * D // gcd(C, D)
print((f(B) - f(A - 1)))
|
p02995
|
# -*- coding: utf-8 -*-
A, B, C, D = list(map(int, input().split()))
ans = 0
Am = 0
Bm = 0
df = 0
t = 0
def lcm(x, y):
return (x * y) // gcd(x, y)
def gcd(a, b):
while b:
a, b = b, a % b
return a
t = B - A + 1
Am = B // C - (A - 1) // C
Bm = B // D - (A - 1) // D
df = B // lcm(C, D) - (A - 1)//lcm(C, D)
ans = t - (Am + Bm) + df
print(ans)
|
# -*- coding: utf-8 -*-
A, B, C, D = list(map(int, input().split()))
ans = 0
Am = 0
Bm = 0
df = 0
t = 0
def lcm(x, y):
return (x * y) // gcd(x, y)
def gcd(a, b):
while b:
a, b = b, a % b
return a
t = B - A + 1
Am = (A - 1) // C + (A - 1) // D - (A - 1)//lcm(C, D)
Bm = B // C + B // D - B // lcm(C, D)
ans = t - (Bm - Am)
print(ans)
|
p02995
|
import sys
from math import gcd
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
A, B, C, D = list(map(int, readline().split()))
G = C // gcd(C, D) * D
c1, c2 = (A + C - 1) // C, B // C
d1, d2 = (A + D - 1) // D, B // D
g1, g2 = (A + G - 1) // G, B // G
ans = (B - A + 1) - ((c2 - c1 + 1) + (d2 - d1 + 1) - (g2 - g1 + 1))
print(ans)
return
if __name__ == '__main__':
main()
|
import sys
from math import gcd
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
A, B, C, D = list(map(int, readline().split()))
L = C // gcd(C, D) * D
c1, c2 = (A + C - 1) // C, B // C
d1, d2 = (A + D - 1) // D, B // D
l1, l2 = (A + L - 1) // L, B // L
ans = (B - A + 1) - ((c2 - c1 + 1) + (d2 - d1 + 1) - (l2 - l1 + 1))
print(ans)
return
if __name__ == '__main__':
main()
|
p02995
|
def solve():
m, n = list(map(int, input().split()))
print((m ** n % 1000000007))
solve()
|
def solve():
m, n = list(map(int, input().split()))
print((pow(m, n, 1000000007)))
solve()
|
p02468
|
MAX = 1000000007
m, n = [int(x) for x in input().split(' ')]
bi_n = bin(n)
ans = 1
dig = m
for i in range(len(bi_n)-1, 1, -1):
if bi_n[i] == '1':
ans *= dig
dig *= dig
if ans >= MAX:
ans %= MAX
print(ans)
|
MAX = 1000000007
m, n = [int(x) for x in input().split(' ')]
bi_n = bin(n)
ans = 1
dig = m
for i in range(len(bi_n)-1, 1, -1):
if bi_n[i] == '1': ans *= dig
if ans >= MAX: ans %= MAX
dig *= dig
if dig >= MAX: dig %= MAX
print(ans)
|
p02468
|
m,n=list(map(int,input().split()))
print((m**n%1000000007))
|
m,n=list(map(int,input().split()))
print((pow(m,n,1000000007)))
|
p02468
|
M = (int)(1e9 + 7)
m, n = list(map(int, input().split()))
ans = 1;
for i in range(n):
ans *= m
ans %= M
print(ans)
|
mod = 1000000007
m, n = list(map(int, input().split()))
print((pow(m,n,mod)))
|
p02468
|
from math import *
def main():
m, n = [int(_) for _ in input().split()]
print((int((m ** n) % 1000000007)))
main()
|
def main():
m, n = [int(_) for _ in input().split()]
print((pow(m, n, 1000000007)))
main()
|
p02468
|
m, n = list(map(int, input().split()))
print((divmod(pow(m, n), 1000000007)[1]))
|
m, n = list(map(int, input().split()))
print((pow(m, n, 1000000007)))
|
p02468
|
def mpow(x,n):
if n == 0:
return 1
if n % 4 == 0:
return mpow(x**4,int(n/4))
elif n%4 == 1:
return mpow(x,int(n-1))*x
elif n%4 == 2:
return mpow(x,int(n-2))*x*x
elif n%4 == 3:
return mpow(x,int(n-3))*x*x*x
n,m = list(map(int,input().split()))
x = 1000000007
print((mpow(n,m)%x))
|
def mpow(x,n,mod):
if n == 0:
return 1
if n % 4 == 0:
return mpow((x**4)%mod,int(n/4),mod)
elif n%4 == 1:
return (mpow(x,int(n-1),mod)*x)%mod
elif n%4 == 2:
return (mpow(x,int(n-2),mod)*(x**2))%mod
elif n%4 == 3:
return (mpow(x,int(n-3),mod)*(x**3))%mod
n,m = list(map(int,input().split()))
mod = 1000000007
print((mpow(n,m,mod)))
|
p02468
|
m, n = list(map(int, input().split()))
mod = 1000000007
print((((m % mod) ** (n % mod)) % mod))
|
m, n = list(map(int, input().split()))
print((pow(m, n, 1000000007)))
|
p02468
|
m, n = list(map(int, input().split()))
p, q, d = 1, m, 1000000007
while True:
if n & 1:
p *= q
p %= d
n >>= 1
if not n:
break
q *= q
q %= d
print(p)
|
m, n = list(map(int, input().split()))
print((pow(m, n, int(1e9) + 7)))
|
p02468
|
m,n=list(map(int,input().split()))
print((m**n%(1000000007)))
|
m,n=list(map(int,input().split()))
print((pow(m,n,1000000007)))
|
p02468
|
m,n = list(map(int,input().split()))
k = m
for i in range(1,n):
m *= k
if m > 1000000007:
m %= 1000000007
print(m)
|
m,n = list(map(int,input().split()))
def amari(m,n):
if n == 0:
return 1
if n % 2 == 0:
return amari(m,n/2)**2%1000000007
else:
return m*amari(m,n-1)%1000000007
print((amari(m,n)))
|
p02468
|
m,n=list(map(int,input().split()))
mn=m**n
if mn<=1000000007:
print(mn)
else:
print((mn%1000000007))
|
m,n=list(map(int,input().split()))
print((pow(m,n,1000000007)))
|
p02468
|
import sys
mod = 10**9 + 7
def solve():
m, n = list(map(int, input().split()))
ans = modpow(m, n, mod)
print(ans)
def modpow(x, y, mod):
res = 1
while y:
if y & 1:
res = (res * x) % mod
x = (x * x) % mod
y >>= 1
return res
if __name__ == '__main__':
solve()
|
import sys
mod = 10**9 + 7
def solve():
m, n = list(map(int, input().split()))
print((pow(m, n, mod)))
if __name__ == '__main__':
solve()
|
p02468
|
try:
(m,n) = list(map(int,input().split()))
except:
exit
r = pow(m,n) % 1000000007
print (r)
|
(m,n) = list(map(int,input().split()))
bi = str(format(n,"b"))
bi = bi[::-1]
c = 1
d = 1000000007
for i in bi:
if ( i == "1"):
c = ( c * m ) % d
m = (m * m) %d
print (c)
|
p02468
|
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
N=ri()
W=[0]*N
ans = 1
for i in range(N):
W[i] = input()
if i != 0 and W[i-1][-1] != W[i][0]:
ans = 0
import collections
Wc = collections.Counter(W).most_common()
if Wc[0][1] != 1:
ans = 0
yn(ans)
|
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
N=ri()
W=[0]*N
ans = 1
for i in range(N):
W[i] = input()
if ans == 1 and i != 0 and W[i-1][-1] != W[i][0]:
ans = 0
if ans == 1 and len(set(W)) != N:
ans = 0
yn(ans)
|
p03261
|
import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()
from collections import defaultdict
N = ni()
W = nsn(N)
d = defaultdict(int)
flag = True
for i in range(N):
if i and W[i - 1][-1] != W[i][0]:
flag = False
if d[W[i]] >= 1:
flag = False
d[W[i]] += 1
print(("Yes" if flag else "No"))
|
import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()
n = ni()
w = nsn(n)
flag = True
dic = dict()
last = w[0][0]
for i in range(n):
if dic.get(w[i], False):
flag = False
if last != w[i][0]:
flag = False
last = w[i][-1]
dic[w[i]] = True
print(("Yes" if flag else "No"))
|
p03261
|
def slove():
import sys
import collections
input = sys.stdin.readline
n = int(input().rstrip('\n'))
lw = ""
d = collections.defaultdict(list)
for i in range(n):
w = str(input().rstrip('\n'))
if lw != "":
if w[0] != lw or w in d:
print("No")
exit()
lw = w[-1]
d[w]
print("Yes")
if __name__ == '__main__':
slove()
|
def slove():
import sys
import collections
input = sys.stdin.readline
n = int(input().rstrip('\n'))
d = collections.defaultdict(int)
s = [str(input().rstrip('\n')) for _ in range(n)]
for i in range(n):
if i != 0:
if s[i][0] != s[i-1][-1] or s[i] in d:
print("No")
exit()
d[s[i]]
print("Yes")
if __name__ == '__main__':
slove()
|
p03261
|
import sys
import collections
def solve():
input = sys.stdin.readline
mod = 10 ** 9 + 7
n = int(input().rstrip('\n'))
s = [str(input().rstrip('\n')) for _ in range(n)]
d = collections.defaultdict(int)
d[s[0]]
b = True
for i in range(1, n):
if s[i] not in d:
d[s[i]]
if s[i][0] != s[i-1][-1]:
b = False
break
else:
b = False
break
print(("Yes" if b else "No"))
if __name__ == '__main__':
solve()
|
import sys
import collections
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n = int(readline())
d = collections.defaultdict(int)
lstr = "1"
for i in range(n):
w = str(readline().rstrip().decode('utf-8'))
if (w[0] == lstr or lstr == "1") and w not in d:
d[w]
lstr = w[-1]
else:
print("No")
exit()
print("Yes")
if __name__ == '__main__':
solve()
|
p03261
|
x = int(eval(input()))
t = 1
ds = {0}
while True:
dc = ds.copy()
for d in dc:
if d + t == x or d - t == x:
break
ds.add(d + t)
ds.add(d - t)
else:
t += 1
continue
break
print(t)
|
from math import ceil, sqrt
x = int(eval(input()))
print((ceil((-1 + sqrt(8 * x + 1)) / 2)))
|
p03781
|
import math
import itertools
X = int(eval(input()))
P = [x for x in range(1, X+1)]
Q = itertools.accumulate(P)
for i, q in enumerate(Q):
if q>=X:
print((i+1))
break
|
X = int(eval(input()))
for i in range(1, X+1):
if i*(i+1)//2 >= X:
print(i)
break
|
p03781
|
x = int(eval(input()))
for i in range(1, x+1):
if sum([j for j in range(1, i+1)]) >= x:
print(i)
break
|
x = int(eval(input()))
for i in range(1, x+1):
if i * (i+1) / 2 >= x:
print(i)
break
|
p03781
|
X=int(eval(input()))
place=[]
time=1
place.append(0)
while True:
next=[]
for i in place:
if i+time not in place:
next.append(i+time)
if i-time not in place:
next.append(i+time)
if X in next:
break
time+=1
place.extend(next)
print(time)
|
X=int(eval(input()))
place=0
time=0
while place<X:
time+=1
place+=time
print(time)
|
p03781
|
str = eval(input())
x = int(str)
res = 1
s = 0
for i in range(1, 10 ** 5):
s = s + i
if s >= x:
res = i
break
print(res)
|
import math
str = eval(input())
x = int(str)
res = math.ceil((-1 + math.sqrt(1 + 8 * x)) / 2.0)
print(res)
|
p03781
|
X = int(eval(input()))
for n in range(1000000):
# print((n * (n - 1) // 2))
if (n * (n - 1) // 2) >= X:
break
print((n - 1))
|
X = int(eval(input()))
# for n in range(1000000):
# # print((n * (n - 1) // 2))
# if (n * (n - 1) // 2) >= X:
# break
# n^2 - n - 2X <= 0
# n = (1 + sqrt(1 + 8X)) // 2
n = max(int((1 + (1 + 8 * X) ** 0.5) / 2) - 1, 0)
while True:
if (n * (n - 1) // 2) >= X:
break
n += 1
print((n - 1))
|
p03781
|
X=int(eval(input()))
i=0
d=0
while d<X:
i+=1
d=i*(i+1)//2
print(i)
|
X=int(eval(input()))
d=0
for i in range(1,X+1):
d+=i
if d>=X:
print(i)
exit()
|
p03781
|
n=int(eval(input()))
p=0
for i in range(1,int(n**0.5)+2):
j,k=divmod(n-i,i)
p+=0 if k or j<=i else j
print(p)
|
n=int(eval(input()))
p=0
for i in range(1,int(n**0.5)+10):
if n%i==0 and n//i-1>i:
p+=n//i-1
print(p)
|
p03050
|
N = int(eval(input()))
ans = 0
for i in range(1,N):
if N % i == 0:
temp = N // i - 1
d,m = divmod(N,temp)
if d != m:
break
else:
ans += temp
print(ans)
|
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
return divisors
N = int(eval(input()))
divisors = make_divisors(N)
ans = 0
divisors.sort(reverse=True)
for x in divisors:
if x > 1:
temp = x - 1
d,m = divmod(N,temp)
if d != m:
break
else:
ans += temp
print(ans)
|
p03050
|
n = int(eval(input()))
ans = 0
for i in range(1, int((n + 1)**0.5)):
if n % i == 0:
ans += n // i - 1
print(ans)
|
n=int(eval(input()))
print((sum(n//i-1 for i in range(1,int((n+1)**0.5)) if n%i<1)))
|
p03050
|
N = int(eval(input()))
ans = 0
for i in range(1, N + 1):
x = (N - i) // i
if x <= i:
break
if (N - i) % i == 0:
ans += x
print(ans)
|
N = int(eval(input()))
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
# divisors.sort()
return divisors
divs = make_divisors(N)
ans = 0
for d in divs:
if d == 1:
continue
m = d - 1
if N // m == N % m:
ans += m
print(ans)
|
p03050
|
# N//m=N%m
# (N-N%m)/m=N%m
# N=(N%m)(m+1)
n=int(eval(input()))
def make_divisor(x):
ret=[]
for i in range(1,int(x**.5)+1):
q,m=divmod(x,i)
if m==0:
ret.append(i)
if i==q:continue
ret.append(q)
return ret
ans=[]
d=make_divisor(n)
for e in d:
if e==1:continue
m=e-1
k=n%m
if k*e==n:
ans.append(m)
print((sum(ans)))
|
# N//m==N%m=k
# N=k*m+k=k(m+1)=kM
N=int(eval(input()))
arr=[]
for i in range(1,int(N**0.5)+1):
if N%i==0:
arr.append(N//i)
if N//i!=i:
arr.append(i)
arr.sort()
ans=0
for M in arr:
m=M-1
if m==0:continue
if N%m==N//m:
ans+=m
print(ans)
|
p03050
|
n = int(eval(input()))
i = 1
ans = 0
while 1:
if (n-i)%i == 0 :
if ((n-i)//i) > i:
ans += (n-i)//i
else:
break
i += 1
print(ans)
|
n = int(eval(input()))
i = 1
ans = 0
r = int(n**(1/2))
for i in range(1,r+1):
if (n-i)%i == 0:
if ((n-i)//i) > i:
ans += (n-i)//i
else:
break
print(ans)
|
p03050
|
n = int(eval(input()))
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
#divisors.sort(reverse=True)
return divisors
d = make_divisors(n)
ans = 0
for a in d:
if a == 1:
continue
else:
q = n//a
m = a-1
if 0 <= q <= m-1:
ans += m
print(ans)
|
n = int(eval(input()))
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
#divisors.sort(reverse=True)
return divisors
D = make_divisors(n)
ans = 0
for d in D:
m = d-1
q = n//d
if m > 0 and 0 <= q < m:
ans += m
print(ans)
|
p03050
|
n=int(eval(input()))
if n==2:
print((0))
exit()
ans=n-1
for i in range(int(n**0.5)+1,2,-1):
# print(n//i+1)
l,r=n//i+1,n//(i-1)+1
while l+1<r:
mid=(l+r)//2
if n//mid<=n%mid:
l=mid
else:
r=mid
if n//l==n%l:
ans+=l
print(ans)
|
n=int(eval(input()))
ans=0
for i in range(1,int(n**0.5)+1):
if n%i==0:
if i>1 and n//(i-1)==n%(i-1):
ans+=i-1
if n//i!=i:
if n//(n//i-1)==n%(n//i-1):
ans+=n//i-1
print(ans)
|
p03050
|
def solve(N):
s = 1
e = int(pow(N, 0.5)) + 1
ds = []
for i in range(s, e):
if N % i == 0:
m = (N // i) - 1
if m and N // m == N % m:
ds.append(N // i)
# print(f"{N} = {m} * {N // m} + {N % m}")
return sum([i - 1 for i in ds])
assert (solve(8) == 3 + 7)
assert (solve(10) == 4 + 9)
assert (solve(1000000000000) == 2499686339916)
if __name__ == "__main__":
N = int(eval(input()))
print((solve(N)))
|
def solve(N):
s = 1
e = int(pow(N, 0.5)) + 1
ds = []
for i in range(s, e):
if N % i == 0:
m = (N // i) - 1
if m and N // m == N % m:
ds.append(N // i)
return sum([i - 1 for i in ds])
if __name__ == "__main__":
N = int(eval(input()))
print((solve(N)))
|
p03050
|
N = int(eval(input()))
ans = 0
for r in range(1,N+1):
if (N-r)%r != 0:
continue
else:
m = (N-r)//r
if m <= r:
break
else:
ans += m
print(ans)
|
N = int(eval(input()))
ans = 0
for r in range(1,int(N**0.5)+2):
if (N-r)%r != 0:
continue
else:
m = (N-r)//r
if m <= r:
break
else:
ans += m
print(ans)
|
p03050
|
n = int(eval(input()))
ans = 0
i = 1
while i*(i+1)+i <= n:
if (n-i) % i == 0:
ans += (n-i)//i
i += 1
print(ans)
|
n = int(eval(input()))
divisors = set()
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.add(i)
divisors.add(n//i)
ans = 0
for d in divisors:
m = d-1
if m != 0 and n//m == n % m:
ans += m
print(ans)
|
p03050
|
import math
from collections import defaultdict
from itertools import product
from functools import reduce
from operator import mul
def is_prime(num):
if not isinstance(num, int):
return False
if num <= 1:
return False
if num == 2 or num == 3:
return True
if num % 6 in [0, 2, 3, 4]:
return False
div_max = int(math.sqrt(num))
for div in range(5, div_max + 1, 2):
if num % div == 0:
return False
return True
def factorint(x):
factors = defaultdict(int)
while not is_prime(x):
div_max = int(math.sqrt(x))
for div in range(2, div_max + 1):
if x % div == 0:
factors[div] += 1
x = int(x / div)
break
factors[x] += 1
return factors
ans = 0
n = int(eval(input()))
if n==0:
print((0))
exit()
rn = math.sqrt(n+1) + 1
factor_dict = factorint(n)
ks = [list(range(k+1)) for k in list(factor_dict.values())]
prs = product(*ks)
for pr in prs:
s = reduce(mul, [factor**p for factor,p in zip(list(factor_dict.keys()), pr)])
if s >= rn:
ans += s -1
print(ans)
|
import math
from collections import defaultdict
from itertools import product
from functools import reduce
from operator import mul
def is_prime(num):
if not isinstance(num, int):
return False
if num <= 1:
return False
if num == 2 or num == 3:
return True
if num % 6 in [0, 2, 3, 4]:
return False
div_max = int(math.sqrt(num))
for div in range(5, div_max + 1, 2):
if num % div == 0:
return False
return True
def factorint(x):
factors = defaultdict(int)
if x==1:
factors[1] = 1
return factors
while not is_prime(x):
div_max = int(math.sqrt(x))
for div in range(2, div_max + 1):
if x % div == 0:
factors[div] += 1
x = int(x / div)
break
factors[x] += 1
return factors
ans = 0
n = int(eval(input()))
rn = math.sqrt(n+1) + 1
factor_dict = factorint(n)
ks = [list(range(k+1)) for k in list(factor_dict.values())]
prs = product(*ks)
for pr in prs:
s = reduce(mul, [factor**p for factor,p in zip(list(factor_dict.keys()), pr)])
if s >= rn:
ans += s -1
print(ans)
|
p03050
|
N=int(eval(input()))
ans = 0
for r in range(1,int(N**(0.5))+10):
if (N-r)%r==0:
m = (N-r)//r
if m!=0 and r == N//m:
ans += m
print(ans)
|
def get_divisor(n):
a,b = [],[]
for i in range(1,int(n**0.5)+1):
if n%i==0:
a.append(i)
b.append(n//i)
if a[-1]==b[-1]:b.pop()
a.extend(b[::-1])
return a
N = int(eval(input()))
ans = 0
for m in get_divisor(N):
m-=1
if m==0 : continue
if N//m == N%m: ans+=m
print(ans)
|
p03050
|
n=int(eval(input()))
ans = 0
for i in range(1,int(n**0.5)+2):
if n%i == 0 and n//i>=i+2:
ans += (n//i)-1
print(ans)
|
def prime(p):
memo = [p]
for i in range(2,(int(p**0.5)+1)):
if p%i == 0:
memo.append(i)
memo.append(p//i)
return memo
x = int(eval(input()))
if x== 1:
print((0))
exit()
memo = prime(x)
ans = 0
for i in memo:
if x%(i-1)==x//(i-1):
ans += i-1
print(ans)
|
p03050
|
n = int(eval(input()))
result = 0
for i in range(1, int(n**(1/2)+1)):
if n%i==0:
x = n//i -1
if x > i:
result += x
print(result)
|
n = int(eval(input()))
print((sum([n//i-1 for i in range(1, int(n**(1/2))+1) if (n%i==0) and (n//i-1 > i)])))
|
p03050
|
n = int(eval(input()))
print((sum([n//i-1 for i in range(1, int(n**(1/2))+1) if n%i==0 and n//i-1>i])))
|
n=int(eval(input()))
print((sum(n//i-1 for i in range(1, int(n**(1/2))+1) if n%i==0 and n//i-1>i)))
|
p03050
|
import math
n = int(eval(input()))
ans = 0
for i in range(1, int(-(-n**0.5//1))+1):
if n%i == 0:
m = n//i - 1
if i < m: ans += m
print(ans)
|
n=int(eval(input()))
ans = 0
for i in range(1,int(n**0.5)+1):
if n%i == 0:
# print('----',i)
a = i
x1 = n//i
x = x1-1
# print(a,x)
if a < x:
ans += x
a = n//i
x1 = i
x = x1 - 1
if a < x:
ans += x
print(ans)
|
p03050
|
from collections import defaultdict
def prime_factorization(n):
'''
Trial division.
Input:
n : a positive integer
Output:
a dictionary of #(each prime factors) of n,
'''
result = defaultdict(int)
if n < 2:
return result
while n % 2 == 0:
result[2] += 1
n //= 2
p = 3
while p*p <= n:
while n % p == 0:
n //= p
result[p] += 1
p += 2
if n > 1:
result[n] += 1
return result
N = int(eval(input()))
ans = 0
if N >= 2:
p = 1
while p*p <= N:
q, r = divmod(N, p)
if r == 0 and p < q - 1:
ans += q - 1
p += 1
print(ans)
|
N = int(eval(input()))
ans = 0
if N >= 2:
p = 1
while p*p <= N:
q, r = divmod(N, p)
if r == 0 and p < q - 1:
ans += q - 1
p += 1
print(ans)
|
p03050
|
N = int(eval(input()))
ans = 0
if N <= 2:
print((0))
exit()
for i in range(1, 10**7):
if (N - i) % i == 0:
tmp = (N - i) // i
if tmp > 1 and tmp > i:
ans += tmp
print(ans)
|
N = int(eval(input()))
ans = 0
if N <= 2:
print((0))
exit()
for i in range(1, 10**6):
if (N - i) % i == 0:
tmp = (N - i) // i
if tmp > 1 and tmp > i:
ans += tmp
print(ans)
|
p03050
|
N = int(eval(input()))
result = 0
for i in range(1, int(N**0.5)+1):
if (N - i) % i == 0 and i ** 2 + i < N:
result += (N - i) // i
print((int(result)))
|
import math
N = int(eval(input()))
result = 0
for i in range(1, math.ceil(((1+4*N)**0.5-1)/2)):
if (N - i) % i == 0:
result += (N - i) // i
print((int(result)))
|
p03050
|
import math
N = int(eval(input()))
ans = 0
for i in range(1, int(math.sqrt(N)) + 1):
if i > N / 2:
continue
tmp = int((N - i) / i)
if (N - i) % i == 0 and N % tmp != 0 and tmp >= math.sqrt(N):
ans += tmp
print(ans)
|
N = int(eval(input()))
def make_divisors(n):
divisors = []
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
return divisors
div = make_divisors(N)
ans = 0
for d in div:
if d != 1 and N // (d - 1) == N % (d - 1):
ans += d - 1
print(ans)
|
p03050
|
N = int(eval(input()))
ans = sum(
(N - q) // q
for q in range(1, int(N**0.5) + 1)
if (N - q) % q == 0 and N // ((N - q) // q) == N % ((N - q) // q)
) if N >= 2 else 0
print(ans)
|
# 入力
N = int(eval(input()))
# sqrt(N) + 1 より大きい N の約数dについて、 d - 1 がお気に入りの数か
# 判定し、お気に入りの数であるものの和を解とする
ans = sum(
N // d - 1
for d in range(1, int(N**0.5) + 1)
if N % d == 0 and N // d > 1 and (N // (N // d - 1)) == (N % (N // d - 1))
)
# 出力
print(ans)
|
p03050
|
import math
N=int(eval(input()))
a=int((math.sqrt(N)//1))
ans=0
if N==2:
print((0))
exit()
for i in range(1,a):
b=(N-i)/i
if b.is_integer():
ans+=int(b)
c=N//a
d=N%a
if int(c)==d:
ans+=a
a+=1
c=N//a
d=N%a
if int(c)==d:
ans+=a
print(ans)
|
N=int(eval(input()))
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
return divisors
A=make_divisors(N)
ans=0
for i in A:
if i==1:
continue
a=N//(i-1)
b=N%(i-1)
if a==b:
ans+=(i-1)
print(ans)
|
p03050
|
N = int(eval(input()))
print((sum((N // n - 1) for n in range(1, int(N ** 0.5) + 1) if not N % n and n < N // n - 1)))
|
N = int(eval(input()))
print((sum(N // n - 1 for n in range(1, int(N ** 0.5) + 1) if not N % n and n < N // n - 1)))
|
p03050
|
N = int(eval(input()))
cnt = 0
for i in range(1,int(N**0.5)+1):
if N%i==0:
q = N//i
m = i-1
if q<m:
cnt += m
m = N//i-1
q = i
if q<m:
cnt += m
print(cnt)
|
N = int(eval(input()))
A = []
for i in range(1,int(N**0.5)+1):
if N%i==0:
a = i
b = N//i
if a>b:
a,b = b,a
if 0<a<b-1:
A.append(b-1)
print((sum(A)))
|
p03050
|
N = int(eval(input()))
A = []
for i in range(1,int(N**0.5)+1):
if N%i==0:
a = i
b = N//i
if a>b:
a,b = b,a
if 0<a<b-1:
A.append(b-1)
print((sum(A)))
|
N = int(eval(input()))
cnt = 0
if N>2:
for x in range(2,int(N**0.5)+1):
if N%x==0:
y = N//x
if N//(x-1)==N%(x-1):
cnt += x-1
if N//(y-1)==N%(y-1):
cnt += y-1
cnt += N-1
print(cnt)
|
p03050
|
n = int(eval(input()))
###商及び余りをsとすると、n=m*s+s=s(m+1)、ただし0<s<m
sum_fav = 0
for s in range(1,n):
if n%s == 0:
m = n//s-1
if s < m:
#print(m)
sum_fav += m
else:
break
print(sum_fav)
|
import math
n = int(eval(input()))
###商及び余りをsとすると、n=m*s+s=s(m+1)、ただし0<s<m
sum_fav = 0
for s in range(1,int(math.sqrt(n))+1):
if n%s == 0:
m = n//s-1
if s < m:
#print(m)
sum_fav += m
else:
break
print(sum_fav)
|
p03050
|
import math
N = int(eval(input()))
ms = []
def solve(N):
result = 0
ms = []
for m in range(1, N):
d, r = divmod(N, m)
if d == r:
result += m
ms.append(m)
return result, ms
def solve1(N):
s = 0
ms = []
for m in range(1, int(math.sqrt(N)+1)):
d, r = divmod(N, m)
if r == 0:
if d < m-1:
s += m - 1
ms.append(m-1)
else:
s += d - 1
ms.append(d-1)
return s, ms
s = 0
cs = set()
for m in range(1, int(math.sqrt(N)+1)):
q, r = divmod(N, m)
if r != 0:
continue
cs.add(q-1)
cs.add(m-1)
def check(c):
if c == 0:
return 0
return c if N // c == N % c else 0
s = sum(check(c) for c in cs)
print(s)
|
import math
N = int(eval(input()))
cs = set()
for m in range(1, int(math.sqrt(N))+1):
q, r = divmod(N, m)
if r != 0:
continue
cs.add(q-1)
cs.add(m-1)
s = sum(c if N // c == N % c else 0 for c in cs if c > 0)
print(s)
|
p03050
|
N = int(eval(input()))
ans = 0
n = 1
while n*n < N:
if (N-n)%n == 0:
m = (N-n)//n
if m <= n: break
ans += m
n += 1
print(ans)
|
N = int(eval(input()))
m = 1
ans = 0
while m*m <= N:
if (N-m)%m == 0:
d = (N-m)//m
if d <= m: break
ans += d
m += 1
print(ans)
|
p03050
|
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
divisors.sort(reverse = True)
return divisors
N = int(eval(input()))
div = make_divisors(N)
i = 0
ans = 0
m = div[0]
while m >= 1:
q = N // m
r = N % m
if q == r:
ans += m
i += 1
m = div[i]
else:
m -= 1
print(ans)
|
N = int(eval(input()))
ans = 0
div = [] # Nの約数を全列挙してdivとする
for i in range(1, int(N ** 0.5) + 1):
if N % i == 0:
div.append(i)
if i != N // i:
div.append(N // i)
for j in range(len(div)):
if div[j] == 1: # m=0はskip
pass
else:
m = div[j] - 1
if N // m == N % m:
ans += m
print(ans)
|
p03050
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.