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 = a... | 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)
... | 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... | 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(e... | 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:
... | 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('infinit... | 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:
... | 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))
... | 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... | #!/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... | 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:
i... | 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
an... | 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:
... | 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:
... | 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:
... | 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 dis... | 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-... | 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))
... | 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()... | #!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()... | 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_c... | #!/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_c... | 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:
... | 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
... | 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 ... | 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 - ... | 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... | 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)... | 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():
... | 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:
... | 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 - ... | 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... | 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)
... | 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_... | 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 =(di... | 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 ... | 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 ... | 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 ite... | #!/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... | 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).
Return... | # -*- 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).
Return... | 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
eli... | 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) ... | 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 - ... | 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-... |
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-... | 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
... | 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(... | #!/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 = (... | 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,... | #@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, ... | 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, ... | #@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 = ... | 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 ... | #!/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 ... | 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
... | 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
... | 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)
... | 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 = l... | 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... | 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... | 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... | 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):
retur... | 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])
... | 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)... | # -*- 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 // lc... | 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... | 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... | 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 = 1... | 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))%... | 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 __... | 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... | 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... | 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 =... | 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... | 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("N... | 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:
... | 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:
... | 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 n... | 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 += ... | 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)
f... | 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... | 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 ... | # 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
... | 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
f... | 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]... | 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()))
... | 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 ... | 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 ... | 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//... | 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):
a... | 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:
... | 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:
re... | 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... | 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... | 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... | 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
... | 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.