problem_id
stringlengths
8
8
id
int64
107k
56M
submission_code
stringlengths
13
515k
abc150_d
10,545,798
import fractions from functools import reduce def lcm1(x,y): return (x*y)//fractions.gcd(x,y) def lcm2(*numbers): return reduce(lcm1,numbers,1) n,m = map(int,input().split()) a = set(map(lambda x: int(x)//2,input().split())) l = lcm2(*a) for i in a: if l // i % 2 == 0: print(0) exit() print(((m // l) + 1) // 2)
abc150_d
12,287,135
from fractions import gcd n,m = map(int,input().split()) A = list(map(int,input().split())) l = 1 cnt = -1 for a in A: l = l*a//gcd(l,a) i = 0 while a%2 == 0: a = a//2 i += 1 if cnt == -1: cnt = i elif cnt != i: print(0) exit(0) ans = 1 + (m - l//2)//l print(ans)
abc150_d
15,499,350
from math import gcd N,M = map(int,input().split()) A = list(map(int,input().split())) d = 1 a = A[0] while a % 2 == 0: d *= 2 a //= 2 if not all((a//d)%2 != 0 and a%d == 0 for a in A): print(0) exit() A = [a//d for a in A] g = 1 for a in A: g = g*a//gcd(g,a) g *= d//2 x = M//g print((x+1)//2)
abc150_d
14,681,995
def lcm(a, b): return a // gcd(a, b) * b def gcd(a, b): if(b == 0): return a else: return gcd(b, a % b) def cnt(a): res = 0 while(a and a % 2 == 0): a //= 2 res += 1 return res n, m = map(int, input().split()) A = list(map(int, input().split())) l = 1 c = cnt(A[0]) for a in A: if cnt(a) != c or c == 0: print(0) exit() else: l = lcm(l, a // 2) d = m // l print((d + 1) // 2)
abc150_d
20,205,674
#!/Users/amitani/Library/PyPy/pypy3.6-v7.3.0-osx64/bin/pypy3 import sys import math def solve(N: int, M: int, A: "List[int]"): # A = [a // 2 for a in A] # if any(not a % 2 for a in A): # print(0) # return MAX_PRIME = 2*10**5 is_prime = [1] * MAX_PRIME is_prime[0] = 0 is_prime[1] = 0 primes = [] for p in range(2, MAX_PRIME): if not is_prime[p]: continue primes.append(p) k = 2 * p while k < MAX_PRIME: is_prime[k] = 0 k += p # def factorize(k): # factors = {} # for p in primes: # if k % p: # continue # if k < p * p: # break # factors[p] = 0 # while k % p == 0: # factors[p] += 1 # k //= p # if k > 1: # factors[k] = 1 # return factors # common_factors = {} # pow def log2(k): res = 0 while not k & 1: res += 1 k >>= 1 return res if len(set(log2(a) for a in A)) > 1: print(0) return R = 1 for a in A: g = math.gcd(R, a) R *= a R //= g # for a in sorted(A, reverse=True): # factors = factorize(a) # pow2.add(factors[2]) # if len(pow2) > 1: # print(0) # return # for p, k in factorize(a).items(): # new_max = max(k, common_factors.get(p, 0)) # R *= p ** (new_max - common_factors.get(p, 0)) # if R > 2 * M: # print(0) # return # common_factors[p] = new_max R //= 2 # print(R) print((M // R + 1) // 2) return # Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int M = int(next(tokens)) # type: int a = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, M, a) if __name__ == '__main__': main()
abc150_d
11,670,922
from itertools import permutations import sys sys.setrecursionlimit(10 ** 6) from bisect import * from collections import * from heapq import * def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def SI(): return sys.stdin.readline()[:-1] def LLI(rows_number): return [LI() for _ in range(rows_number)] int1 = lambda x: int(x) - 1 def MI1(): return map(int1, sys.stdin.readline().split()) def LI1(): return list(map(int1, sys.stdin.readline().split())) p2D = lambda x: print(*x, sep="\n") dij = [(1, 0), (0, 1), (-1, 0), (0, -1)] def gcd(a,b): while b:a,b=b,a%b return a def lcm(a,b): return a*b//gcd(a,b) def main(): n,k=MI() aa=LI() aa2=[a//2 for a in aa] l=1 for a2 in aa2:l=lcm(l,a2) for a2 in aa2: if l//a2%2==0: print(0) exit() print((k//l+1)//2) main()
abc150_d
11,671,383
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()] def I(): return int(sys.stdin.buffer.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(): def gcd(a,b): if a == 0: return b return gcd(b%a,a) n,m = LI() a = LI() s = set() for i in a: k = 0 while not i&1: i >>= 1 k += 1 if not k: print(0) return s.add(k) if len(s) != 1: print(0) return a = [i >> 1 for i in a] l = a[0] for i in a[1:]: g = gcd(l,i) l = l*i//g print((m//l)-(m//(2*l))) return #Solve if __name__ == "__main__": solve()
abc150_d
11,672,700
from fractions import gcd def lcm(a, b): return a * b // gcd(a, b) n,m = map(int,input().split()) a = list(map(int,input().split())) b = [i // 2 for i in a] def f(n): res = 0 while n % 2 == 0: res += 1 n //= 2 return res if not all(f(b[0]) == f(b[i]) for i in range(n)): print(0) exit(0) cnt = f(b[0]) g = b[0] >> cnt for i in b: g = lcm(g, i >> cnt) gg = g << cnt print((m + gg) // (2 * gg))
abc150_d
11,673,075
n,m=map(int,input().split()) a = list(map(int, input().split())) def gcd(a,b): if(b==0): return a else: return gcd(b,a%b) def lcm(a,b): return a*b//gcd(a,b) b=[0]*n for i in range(n): b[i]=a[i]//2 flag=False f=0 keta=0 buf=b[0] while(buf%2==0): buf/=2 keta+=1 for i in range(n): buf=b[i] tmp=0 while(buf%2==0): buf/=2 tmp+=1 if(keta!=tmp): flag=True x=1 if(b[0]%2==0): f=1 for i in range(n): x=lcm(x,b[i]) res=m//x+1 res//=2 #print(x) if(flag): print(0) else: print(res)
abc150_d
20,217,553
from math import gcd n, m = map(int, input().split()) a = list(set(map(int, input().split()))) n = len(a); lcm = a[0]; z = 0 for i in range(1, n): lcm = lcm*a[i]//gcd(lcm, a[i]) if lcm > 2*m: z = 1; break if z == 0: for i in range(n): if (lcm//a[i])%2 == 0: z = 1; break print((m+lcm//2)//lcm) if z == 0 else print(0)
abc150_d
30,758,849
import sys, random input = lambda : sys.stdin.readline().rstrip() write = lambda x: sys.stdout.write(x+"\n"); writef = lambda x: print("{:.12f}".format(x)) debug = lambda x: sys.stderr.write(x+"\n") YES="Yes"; NO="No"; pans = lambda v: print(YES if v else NO); inf=10**18 LI = lambda : list(map(int, input().split())) def dlist(*l, fill=0): if len(l)==1: return [fill]*l[0] ll = l[1:] return [dlist(*ll, fill=fill) for _ in range(l[0])] sys.setrecursionlimit(3*10**5+10) from math import gcd n,m = list(map(int, input().split())) a = LI() a = [v//2 for v in a] count = [0]*2 for v in a: count[v%2] += 1 if count[0] and count[1]: ans = 0 elif count[0]==0: l = a[0] for v in a[1:]: g = gcd(l,v) l = l*v//g if l>m: break tmp = m//l ans = (tmp+1)//2 else: l = a[0] for v in a[1:]: g = gcd(l,v) l = l*v//g if l>m: ans = 0 break else: if all(((l//v)%2==1 for v in a)): tmp = m//l ans = (tmp+1)//2 else: ans = 0 print(ans)
abc150_d
15,532,220
from math import gcd n, m = map(int, input().split()) A = list(map(int, input().split())) A = [a//2 for a in A] lcm = 1 for i in range(n): lcm = lcm * A[i] // gcd(lcm, A[i]) if lcm > m: print(0) exit() for a in A: if lcm // a % 2 == 0: print(0) exit() print((m//lcm + 1) // 2)
abc150_d
20,228,740
import sys from sys import exit, stdin from collections import deque, defaultdict from copy import deepcopy from bisect import bisect_left, bisect_right, insort_left, insort_right from heapq import heapify, heappop, heappush from itertools import product, permutations, combinations, combinations_with_replacement from functools import reduce from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians, ceil, floor from math import pi as PI # from decimal import Decimal sys.setrecursionlimit(10**6) INF = float('inf') EPS = 1e-10 MOD = 10**9+7 # MOD = 998244353 def input(): return stdin.readline()[:-1] def intput(): return int(stdin.readline()) def minput(): return stdin.readline()[:-1].split() def mint(): return map(int,stdin.readline().split()) def linput(): return list(stdin.readline()[:-1].split()) def lint(): return list(map(int,stdin.readline().split())) def iint(): return int(stdin.readline()), stdin.readline()[:-1] def ilint(): return int(stdin.readline()), list(map(int,stdin.readline().split())) def lcm(x,y): return x*y//gcd(x,y) def lgcd(l): return reduce(gcd,l) def llcm(l): return reduce(lcm,l) def powmod(n,i,mod=MOD): return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod) def div2(x): return x.bit_length() def div10(x): return len(str(x))-(x==0) def popcount(x): return bin(x).count('1') def digit(x,i,max_len=None): s = str(x) if max_len: i -= max_len-len(s) return int(s[i-1]) if i>0 else 0 def digitsum(x): ans = 0 for i in range(div10(x)): ans += digit(x,i+1) return ans class counter(defaultdict): def __init__(self, *args): super().__init__(int) def add(self,x,d=1): self[x] += d def to_list(self): l = [] for x in sorted(self.keys()): l.extend([x]*self[x]) return l def pf(x,mode='set'): C = counter() p = 2 while x>1: k = 0 while x%p==0: x //= p k += 1 if k>0: C.add(p,k) p = p+2-(p==2) if p*p<x else x if mode=='counter': return C S = set([1]) for k in C: T = deepcopy(S) for x in T: for i in range(1,C[k]+1): S.add(x*(k**i)) if mode=='set': return S if mode=='list': return sorted(S) def pr(*x): print(x[0],end='') if len(x) else print('') def lprint(l): print(*l,sep='\n') def ston(c, c0='a'): return ord(c)-ord(c0) def ntos(x, c0='a'): return chr(x+ord(c0)) def judge(x, l=['Yes', 'No']): print(l[0] if x else l[1]) ###################################################### N,M=mint() A=lint() def f(x): c=0 while not x%2: x//=2 c+=1 return x,c lc,cn2=f(A[0]) for a in A[1:]: x,c=f(a) lc=lcm(lc,x) if c!=cn2 or 2**(cn2-1)*lc>M: print(0) exit() print((M-2**(cn2-1)*lc)//(2**cn2*lc)+1)
abc150_d
9,395,610
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from fractions import gcd from functools import reduce N,M,*A = map(int,read().split()) # 「奇数倍」に帰着 A = [x >> 1 for x in A] def merge(a,b): g = gcd(a,b) a //= g; b //= g if a % 2 == 0: return 0 if b % 2 == 0: return 0 n = a * b * g if n > 10 ** 9: return 0 return n x = reduce(merge, A) if x == 0: answer = 0 else: answer = (M//x) - (M//(x+x)) print(answer)
abc150_d
9,908,516
n,m = map(int,input().split()) a = list(map(int,input().split())) b = 1 while a[0] % 2 == 0: a[0] //= 2 b *= 2 if b == 0: print(0) else: for i in range(1,n): a[i] //= b if a[i] % 2 == 0: print(0) break else: m //= b//2 lcm = a[0] for i in range(1,n): big,sml = lcm,a[i] while sml != 0: big,sml = sml,big%sml lcm *= a[i] // big if lcm > m: print(0) break else: m -= lcm ans = 1 lcm *= 2 ans += m // lcm print(ans)
abc150_d
9,394,683
from fractions import gcd def solve(n, m, aaa): lcm = 1 for a in aaa: a //= 2 lcm *= a // gcd(lcm, a) if lcm > m: return 0 for a in aaa: if int(lcm / a) == lcm / a: return 0 return (m // lcm + 1) // 2 n, m = list(map(int, input().split())) aaa = list(map(int, input().split())) print(solve(n, m, aaa))
abc150_d
9,410,187
from functools import reduce def gcd(a, b): while b: a, b = b, a % b return abs(a) def lcm(a, b): return a*b//gcd(a, b) N, M = map(int, input().split()) A = [int(a)//2 for a in input().split()] B = [a & -a for a in A] if min(B) != max(B): print(0) else: l = reduce(lcm, A) print(M // l - M // l // 2)
abc150_d
9,400,194
def gcd(a: int, b: int) -> int: """a, bの最大公約数(greatest common divisor:GCD)を求める 計算量: O(log(min(a, b))) """ if b == 0: return a return gcd(b, a%b) def lcm(a, b): """a, bの最小公倍数(least common multiple:LCM)を求める 計算量: O(log(min(a, b)))""" return (a * b) // gcd(a, b) def multi_lcm(array, m): """arrayのLCMを求める""" ans = array[0] for i in range(1, len(array)): ans = (ans * array[i]) // gcd(ans, array[i]) if ans > 5*m: return 5*m return ans import sys input = sys.stdin.readline n, m = map(int, input().split()) a = list(map(int, input().split())) l = [0] * n for i in range(n): cnt = 0 tmp = a[i] while True: if tmp % 2 == 0: cnt += 1 tmp //= 2 else: break l[i] = cnt if max(l) != min(l): print(0) exit() div = multi_lcm(a, m) ans = 0 if m - div // 2 >= 0: ans += 1 m = m - div // 2 ans += m // div if m < 0: print(0) else: print(ans)
abc150_d
9,396,435
N, M = list(map(int, input().split())) A = list(map(int, input().split())) A = [a//2 for a in A] K = [] for i, a in enumerate(A): k = 0 while a%2==0: a//=2 k+=1 K.append(k) A[i] = a if len(set(K))>1: print(0) exit() def gcd(a,b): if a>b: a,b = b,a while a: a,b=b%a, a return b def lcm(a,b): return a*b//gcd(a,b) l = 1 for a in A: l = lcm(l,a) l *= 2**K[0] print((M+l)//(l*2))
abc150_d
9,408,727
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines #a,bの最大公約数 def gcd(a,b): if b == 0: return a else: return gcd(b,a%b) #a,bの最小公倍数 def lcm(a,b): return a*b//gcd(a,b) N,M = map(int,readline().split()) A = list(map(int,readline().split())) B = [A[i]//2 for i in range(N)] ans = 1 dev_c = 0 while A[0]%2 != 1: A[0] = A[0]//2 dev_c += 1 #print(dev_c) for i in range(1,N): dev_c2 = 0 while A[i]%2 != 1: A[i] = A[i]//2 dev_c2 += 1 if dev_c != dev_c2: ans = 0 break l = B[0] if ans == 1: for i in range(N): l = lcm(l,B[i]) #print(l) if ans != 0: ans = (M//l+1)//2 print(ans)
abc150_d
9,398,083
n,m = map(int,input().split()) a = list(map(int,input().split())) cnt = 0 while True: if a[0] % 2 == 0: a[0] //= 2 cnt += 1 else: break div = 2 ** cnt if div != 1: m //= (div//2) for i in range(1,n): if a[i] % div == 0: a[i] //= div if a[i] % 2 == 0: print(0) break else: print(0) break if cnt == 0: print(0) break else: #print(a) lcm = a[0] for i in range(1,n): big,sml = a[i],lcm while sml != 0: big,sml = sml,big%sml lcm *= a[i] // big #print(lcm) ans = m // (2*lcm) #print(ans) if m % (2*lcm) >= lcm: ans += 1 print(ans)
abc150_d
9,409,006
def main(): from fractions import gcd n, m = map(int, input().split()) a = list(map(int, input().split())) a = [i//2 for i in a] g = a[0] s = set() for i in a: cnt = 0 while i % 2 == 0: i //= 2 cnt += 1 s.add(cnt) if len(s) == 1: for i in a[1:]: g = (g*i)//gcd(g, i) print((m//g+1)//2) else: print(0) main()
abc150_d
9,393,296
def main(): import sys from fractions import gcd input = sys.stdin.readline N, K = map(int, input().split()) A = list(map(int, input().split())) A_ = [a//2 for a in A] lcm = A_[0] t_num = 0 a = A_[0] while a % 2 == 0: t_num += 1 a //= 2 for a in A_: lcm = (lcm * a) // gcd(a, lcm) t_n = 0 while a % 2 == 0: t_n += 1 a //= 2 if t_n != t_num: print(0) exit() ans = K // lcm print((ans+1)//2) if __name__ == '__main__': main()
abc150_d
9,403,212
#!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop from itertools import permutations 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(): def gcd(a,b): if a == 0: return b return gcd(b%a,a) n,m = LI() a = LI() b = [i >> 1 for i in a] c = [i&1 for i in b] c.sort() while 1: if c[0] == 1: break if c[0] == 0 and c[-1] == 1: print(0) return b = [i >> 1 for i in b] c = [i&1 for i in b] c.sort() m >>= 1 l = b[0] for i in b[1:]: if l&1 != i&1: print(0) return g = gcd(l,i) l = l*i//g if l > m: print(0) return L = l l = 0 r = m+1 while r-l > 1: x = (l+r) >> 1 if (2*x-1)*L <= m: l = x else: r = x print(l) return #Solve if __name__ == "__main__": solve()
abc150_d
9,408,943
def main(): from fractions import gcd n, m = map(int, input().split()) a = list(map(int, input().split())) a = [i//2 for i in a] g = a[0] s = set() for i in a: j = i cnt = 0 while j % 2 == 0: j //= 2 cnt += 1 s.add(cnt) if len(s) >= 1: if len(s) == 1: for i in range(n-1): g = (g*a[i+1])//gcd(g, a[i+1]) print((m//g+1)//2) return else: print(0) return for i in range(n-1): g = (g*a[i+1])//gcd(g, a[i+1]) print((m//g+1)//2) main()
abc150_d
9,409,954
import fractions n,m = map(int,input().split()) l = input().split() lcm = 1 sum = 0 for i in range(len(l)): lcm = (int(l[i]) * lcm) // fractions.gcd(int(l[i]), lcm) for i in range(len(l)): if (lcm // int(l[i])) % 2 == 1: sum += 1 if sum == len(l): x = m // (int(lcm) // 2) y = m // lcm print(int(x - y)) else: print(0)
abc150_d
9,396,275
import sys from fractions import gcd input = sys.stdin.readline N, M = map(int, input().split()) a = list(map(int, input().split())) gh = 0 l = 1 dbl = [0] * N for i in range(N): x = a[i] t = 0 while x % 2 == 0: x //= 2 t += 1 dbl[i] = t if max(dbl) != min(dbl): print(0) exit(0) t = pow(2, dbl[0]) s = set() for i in range(N): if a[i] in s: continue s.add(a[i]) l *= a[i] // t // gcd(l, a[i]) if l > M: print(0) exit(0) l *= t // 2 print(M // l - M // (2 * l))
abc150_d
9,407,891
# coding: utf-8 # Your code here! import sys sys.setrecursionlimit(10**6) readline = sys.stdin.readline read = sys.stdin.read n,m = [int(i) for i in readline().split()] a = [int(i)//2 for i in read().split()] #2で割れる回数 def num_of_2(x): c = 0 while x%2 == 0: c += 1 x //= 2 return c #最小公倍数 from fractions import gcd def lcm(x,y): return x//(gcd(x,y))*y #2で割れる回数が違ったらアウト a0 = num_of_2(a[0]) if any([num_of_2(i) != a0 for i in a]): print(0) else: #最小公倍数が c のとき、c,3c,5c,... が条件をみたす c = 1 for i in a: c = lcm(c,i) if c > m: break #mを超えたらもう無意味 print((m//c+1)//2)
abc150_d
9,411,539
import sys readline = sys.stdin.readline def gcd(a,b): if b == 0: return a return gcd(b,a%b) def lcm(a, b): return a*b//gcd(a, b) N, M = map(int, readline().split()) A = list(map(int, readline().split())) B = [a//2 for a in A] L = 1 for b in B: L = lcm(L, b) ans = 0 if all((L//b) & 1 for b in B): ok = 0 ng = M*2 while abs(ok-ng) > 1: med = (ok+ng)//2 if (med*2-1)*L <= M: ok = med else: ng = med print(ok) else: print(ans)
abc150_d
9,396,439
import sys def input(): return sys.stdin.readline()[:-1] from fractions import gcd n, m = map(int, input().split()) a = list(map(int, input().split())) m *= 2 if n == 1: print((m//a[0]+1)//2) else: lcm = a[0]*a[1]//gcd(a[0], a[1]) for i in range(2, n): lcm = lcm * a[i] // gcd(lcm, a[i]) if lcm > m: print(0) sys.exit() divs = 0 for x in a: divs += (lcm//x)%2 if divs < n: print(0) else: print((m//lcm+1)//2)
abc150_d
9,412,720
import sys from fractions import gcd sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 def input(): return sys.stdin.readline().rstrip() def main(): N,M=map(int,input().split()) a=tuple(map(lambda x:int(x)//2,input().split())) t=a[0] c=0 while True: if t%2==0: c+=1 t//=2 else: break l=a[0] for x in a[1:]: if x%(2**c)!=0 or x%(2**(c+1))==0: print(0) exit() l=l*x//gcd(l,x) print((M+l)//(l*2)) if __name__ == '__main__': main()
abc150_d
9,408,758
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines #a,bの最大公約数 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) N,M = map(int,readline().split()) A = list(map(int,readline().split())) B = [A[i]//2 for i in range(N)] ans = 1 dev_c = 0 while A[0]%2 != 1: A[0] = A[0]//2 dev_c += 1 #print(dev_c) for i in range(1,N): dev_c2 = 0 while A[i]%2 != 1: A[i] = A[i]//2 dev_c2 += 1 if dev_c != dev_c2: ans = 0 break l = B[0] if ans == 1: for i in range(N): l = lcm(l,B[i]) #print(l) if ans != 0: ans = (M//l+1)//2 print(ans)
abc150_d
11,732,302
def gcd(a, b): while b: a, b = b, a % b return a def lcm(a, b): return a * b // gcd(a, b) n, m = map(int, input().split()) a = list(map(int, input().split())) l = a[0] // 2 for i in range(n): a[i] //= 2 l = lcm(l, a[i]) c = 0 while True: for i in range(n): if a[i] % 2 == 1: c += 1 else: a[i] //= 2 if not c == 0: break print(((m // l) + 1) // 2 if c == n else 0)
abc150_d
20,253,358
from bisect import * from collections import * from math import gcd,ceil,sqrt,floor,inf from heapq import * from itertools import * from operator import add,mul,sub,xor,truediv,floordiv from functools import * #------------------------------------------------------------------------ import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #------------------------------------------------------------------------ def RL(): return map(int, sys.stdin.readline().rstrip().split()) def RLL(): return list(map(int, sys.stdin.readline().rstrip().split())) def N(): return int(input()) def A(n):return [0]*n def AI(n,x): return [x]*n def G(n): return [[] for i in range(n)] def GP(it): return [[ch,len(list(g))] for ch,g in groupby(it)] #------------------------------------------------------------------------ from types import GeneratorType def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc mod=10**9+7 farr=[1] ifa=[] def fact(x,mod=0): if mod: while x>=len(farr): farr.append(farr[-1]*len(farr)%mod) else: while x>=len(farr): farr.append(farr[-1]*len(farr)) return farr[x] def ifact(x,mod): global ifa fact(x,mod) ifa.append(pow(farr[-1],mod-2,mod)) for i in range(x,0,-1): ifa.append(ifa[-1]*i%mod) ifa.reverse() def per(i,j,mod=0): if i<j: return 0 if not mod: return fact(i)//fact(i-j) return farr[i]*ifa[i-j]%mod def com(i,j,mod=0): if i<j: return 0 if not mod: return per(i,j)//fact(j) return per(i,j,mod)*ifa[j]%mod def catalan(n): return com(2*n,n)//(n+1) def isprime(n): for i in range(2,int(n**0.5)+1): if n%i==0: return False return True def floorsum(a,b,c,n):#sum((a*i+b)//c for i in range(n+1)) if a==0:return b//c*(n+1) if a>=c or b>=c: return floorsum(a%c,b%c,c,n)+b//c*(n+1)+a//c*n*(n+1)//2 m=(a*n+b)//c return n*m-floorsum(c,c-b-1,a,m-1) def inverse(a,m): a%=m if a<=1: return a return ((1-inverse(m,a)*m)//a)%m def lowbit(n): return n&-n class BIT: def __init__(self,arr): self.arr=arr self.n=len(arr)-1 def update(self,x,v): while x<=self.n: self.arr[x]+=v x+=x&-x def query(self,x): ans=0 while x: ans+=self.arr[x] x&=x-1 return ans class ST: def __init__(self,arr):#n!=0 n=len(arr) mx=n.bit_length()#取不到 self.st=[[0]*mx for i in range(n)] for i in range(n): self.st[i][0]=arr[i] for j in range(1,mx): for i in range(n-(1<<j)+1): self.st[i][j]=max(self.st[i][j-1],self.st[i+(1<<j-1)][j-1]) def query(self,l,r): if l>r:return -inf s=(r+1-l).bit_length()-1 return max(self.st[l][s],self.st[r-(1<<s)+1][s]) ''' class DSU:#容量+路径压缩 def __init__(self,n): self.c=[-1]*n def same(self,x,y): return self.find(x)==self.find(y) def find(self,x): if self.c[x]<0: return x self.c[x]=self.find(self.c[x]) return self.c[x] def union(self,u,v): u,v=self.find(u),self.find(v) if u==v: return False if self.c[u]>self.c[v]: u,v=v,u self.c[u]+=self.c[v] self.c[v]=u return True def size(self,x): return -self.c[self.find(x)]''' class UFS:#秩+路径 def __init__(self,n): self.parent=[i for i in range(n)] self.ranks=[0]*n def find(self,x): if x!=self.parent[x]: self.parent[x]=self.find(self.parent[x]) return self.parent[x] def union(self,u,v): pu,pv=self.find(u),self.find(v) if pu==pv: return False if self.ranks[pu]>=self.ranks[pv]: self.parent[pv]=pu if self.ranks[pv]==self.ranks[pu]: self.ranks[pu]+=1 else: self.parent[pu]=pv def Prime(n): c=0 prime=[] flag=[0]*(n+1) for i in range(2,n+1): if not flag[i]: prime.append(i) c+=1 for j in range(c): if i*prime[j]>n: break flag[i*prime[j]]=prime[j] if i%prime[j]==0: break return flag def dij(s,graph): d={} d[s]=0 heap=[(0,s)] seen=set() while heap: dis,u=heappop(heap) if u in seen: continue seen.add(u) for v,w in graph[u]: if v not in d or d[v]>d[u]+w: d[v]=d[u]+w heappush(heap,(d[v],v)) return d def lcm(a,b): return a*b//gcd(a,b) def lis(nums): res=[] for k in nums: i=bisect.bisect_left(res,k) if i==len(res): res.append(k) else: res[i]=k return len(res) def RP(nums):#逆序对 n = len(nums) s=set(nums) d={} for i,k in enumerate(sorted(s),1): d[k]=i bi=BIT([0]*(len(s)+1)) ans=0 for i in range(n-1,-1,-1): ans+=bi.query(d[nums[i]]-1) bi.update(d[nums[i]],1) return ans class DLN: def __init__(self,val): self.val=val self.pre=None self.next=None def nb(i,j,n,m): for ni,nj in [[i+1,j],[i-1,j],[i,j-1],[i,j+1]]: if 0<=ni<n and 0<=nj<m: yield ni,nj def topo(n): q=deque() res=[] for i in range(1,n+1): if ind[i]==0: q.append(i) res.append(i) while q: u=q.popleft() for v in g[u]: ind[v]-=1 if ind[v]==0: q.append(v) res.append(v) return res @bootstrap def gdfs(r,p): if len(g[r])==1 and p!=-1: yield None for ch in g[r]: if ch!=p: yield gdfs(ch,r) yield None t=1 for i in range(t): n,m=RL() a=RLL() c=A(n) for i,x in enumerate(a): while not x&1: x//=2 c[i]+=1 a[i]=x if any(x!=c[0] for x in c): ans=0 else: ans=0 cur=a[0] for i in range(1,n): cur=cur*a[i]//gcd(cur,a[i]) if cur>m:break cur*=pow(2,c[0]-1) if cur<=m: t=m//cur ans=(t+1)//2 print(ans) ''' sys.setrecursionlimit(200000) import threading threading.stack_size(10**8) t=threading.Thr ead(target=main) t.start() t.join() ''' ''' sys.setrecursionlimit(200000) import threading threading.stack_size(10**8) t=threading.Thread(target=main) t.start() t.join() '''
abc150_d
9,438,382
n,m = map(int, input().split()) l = list(map(int, input().split())) g = l.copy() while not any(x%2 for x in g): g = [x//2 for x in g] if not all(x%2 for x in g): print(0); exit(0) def gcd(a,b): while b: a,b = b,a%b return a lcm = lambda a,b: a*b//gcd(a,b) tot = 1 for x in l: tot = lcm(tot,x//2) print((m//tot+1)//2)
abc150_d
9,411,423
import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def gcd(x,y): while y:x,y=y,x%y return x def lcm(x,y): g=gcd(x,y) return x*y//g def main(): n,m=MI() aa=LI() aa=[a>>1 for a in aa] l=1 for a in aa:l=lcm(l,a) for a in aa: if l//a%2==0: print(0) exit() print((m//l+1)//2) main()
abc150_d
9,408,780
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines #a,bの最大公約数 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) N,M = map(int,readline().split()) A = list(map(int,readline().split())) B = [A[i]//2 for i in range(N)] ans = 1 dev_c = 0 while A[0]%2 != 1: A[0] = A[0]//2 dev_c += 1 #print(dev_c) for i in range(1,N): dev_c2 = 0 while A[i]%2 != 1: A[i] = A[i]//2 dev_c2 += 1 if dev_c != dev_c2: ans = 0 break l = B[0] if ans == 1: for i in range(N): l = lcm(l,B[i]) #print(l) if ans != 0: ans = (M//l+1)//2 print(ans)
abc150_d
9,406,207
from fractions import gcd import sys input = sys.stdin.readline def main(): N, M = map(int, input().split()) A = list(map(int, input().split())) B = [] ok = True a = A[0] c = 0 while a%2 == 0: a //= 2 c += 1 p = 2**c for a in A: if a % p == 0 and a % (2*p) != 0: B.append(a//p) else: ok = False break if not ok: print(0) else: B.sort() g = 1 for b in B: l = gcd(b, g) g = g*b//l if g > M: ok = False break if not ok: print(0) else: p = g*2**(c-1) ans = (M+p)//(2*p) print(ans) if __name__ == "__main__": main()
abc150_d
20,253,579
import math #2で割り切れる回数 def f(x): if x%2==1: return 0 else: return f(x//2)+1 n,m=map(int,input().split()) a=list(map(int,input().split())) num=1 flag=True for i in a: num=num*i//math.gcd(num,i)//2 if f(a[0])!=f(i): flag=False ans=0 if m>=num and flag: ans=1+(m-num)//(2*num) print(ans)
abc150_d
10,746,537
from fractions import gcd N, M = map(int, input().split()) a = list(map(int, input().split())) b = [0] * N for i in range(N): tmp = a[i] while tmp & 1 == 0: tmp = tmp>>1 b[i] += 1 same = True ct = b[0] for i in range(1, N): if b[i] != ct: same = False if not same: print(0) else: plcm = 1 for i in range(N): if plcm > M: plcm = M+1 else: a[i] //= 2 plcm = plcm * (a[i] // gcd(plcm, a[i])) if plcm > M: print(0) else: ansd = M // plcm ans = (ansd + 1)//2 print(ans)
abc150_d
9,486,831
import sys input = sys.stdin.readline N,M=map(int,input().split()) A=list(map(int,input().split())) def gcd(a, b): while b: a, b = b, a % b return a def lcm(x, y): return (x * y) // gcd(x, y) def count2(x): c=0 while x%2==0: x//=2 c+=1 return c c2=count2(A[0]) LCM=1 for a in A: if count2(a)!=c2: print(0) sys.exit() LCM=lcm(a//2,LCM) if LCM>M: print(0) sys.exit() print(max(0,(M-LCM)//(2*LCM)+1))
abc150_d
9,405,333
from fractions import gcd from functools import reduce N, M = map(int, input().split()) A = list(map(int, input().split())) AA = list(map(lambda x: x//2, A)) def lcm(x, y): return x * y // gcd(x, y) b0 = AA[0]&-AA[0] for a in AA[1:]: if b0 != a&-a: print(0) break else: a = reduce(lcm, AA) print(M//a - M//(2*a))
abc150_d
10,114,227
def gcd(n,m):#n,mは正の整数、最大公約数 許容は? if n==0: return m elif m==0: return n elif n>m: n=n%m return gcd(n,m) else: m=m%n return gcd(n,m) N,M=map(int,input().split()) A=list(map(int,input().split())) realA=[A[i]//2 for i in range(0,N)] lcm=realA[0] flag=0 if N==1: print((M//lcm+1)//2) else: for i in range(0,N-1): x=lcm lcm=lcm*realA[i+1]//(gcd(lcm,realA[i+1])) if (lcm**2//(realA[i+1]*x))%2==0: flag=1 break if flag==0: print((M//lcm+1)//2) else: print(0)
abc150_d
9,408,696
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines #a,bの最大公約数 def gcd(a,b): if b == 0: return a else: return gcd(b,a%b) #a,bの最小公倍数 def lcm(a,b): return a*b//gcd(a,b) N,M = map(int,readline().split()) A = list(map(int,readline().split())) B = [A[i]//2 for i in range(N)] ans = 1 dev_c = 0 while A[0]%2 != 1: A[0] = A[0]//2 dev_c += 1 #print(dev_c) for i in range(1,N): dev_c2 = 0 while A[i]%2 != 1: A[i] = A[i]//2 dev_c2 += 1 if dev_c != dev_c2: ans = 0 break l = B[0] if ans == 1: for i in range(N): l = lcm(l,B[i]) #print(l) if ans != 0: ans = (M//l+1)//2 print(ans)
abc150_d
17,695,663
#!/usr/bin/python3 import sys from functools import reduce from math import gcd input = lambda: sys.stdin.readline().strip() n, m = [int(x) for x in input().split()] a = [int(x) for x in input().split()] LIM = 10**18 powers_of_2 = [1] while powers_of_2[-1] <= LIM: powers_of_2.append(powers_of_2[-1] * 2) def lcm(x, y): return min(x * y // gcd(x, y), LIM) if any(all(ai % (power * 2) == power for ai in a) for power in powers_of_2): l = reduce(lcm, a) print(0 if m - l // 2 < 0 else (m - l // 2) // l + 1) else: print(0)
abc150_d
12,497,313
def GCD(x, y): if y == 0: return x return GCD(y, x % y) N, M = map(int, input().split()) A = list(map(int, input().split())) A = sorted(set(A)) check = set() for a in A: cnt = 0 while a % 2 == 0: cnt += 1 a //= 2 check.add(cnt) if len(check) > 1: print(0) exit() LCM = 1 for a in A: gcd = GCD(LCM, a // 2) LCM = LCM * (a // 2) // gcd ans = (M - LCM) // (2 * LCM) + 1 print(ans)
abc150_d
22,677,564
from math import gcd import sys #Library Info(ACL for Python/Pypy) -> https://github.com/not522/ac-library-python def input(): return sys.stdin.readline().rstrip() def lcm(a, b): return a * b // gcd(a, b) def main(): N, M = map(int, input().split()) A = list(map(lambda x: int(x) // 2, input().split())) B = [0]*(N) for i in range(N): v = A[i] while v % 2 == 0: B[i] += 1 v //= 2 if not all(B[i] == B[0] for i in range(N)): print(0) return Lcm = 1 for v in A: while(v % 2 == 0): v //= 2 assert v % 2 != 0 Lcm = lcm(Lcm, v) if Lcm >= 10**18: print(0) return val = (1 << B[0]) * Lcm ans = (M // val + 1) // 2 print(ans) return 0 if __name__ == "__main__": main()
abc150_d
11,198,439
#!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop from itertools import permutations 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(): def gcd(a,b): if a == 0: return b return gcd(b%a,a) n,m = LI() a = LI() k = [i&-i for i in a] if len(set(k)) > 1 or all([i == 1 for i in k]): print(0) return a = [i>>1 for i in a] l = a[0] for i in a[1:]: g = gcd(l,i) l *= i//g print(m//l-m//(2*l)) return #Solve if __name__ == "__main__": solve()
abc150_d
17,708,658
#!/usr/bin/python3 import sys from functools import reduce from math import gcd input = lambda: sys.stdin.readline().strip() n, m = [int(x) for x in input().split()] a = [int(x) for x in input().split()] def pow2in(x): return 0 if x % 2 else 1 + pow2in(x // 2) def lcm(x, y): return min(x * y // gcd(x, y), 10**18) if len(set(pow2in(ai) for ai in a)) == 1: l = reduce(lcm, a) print(0 if m - l // 2 < 0 else (m - l // 2) // l + 1) else: print(0)
abc150_d
10,507,154
import fractions from functools import reduce def lcm_base(x, y): return (x * y) // fractions.gcd(x, y) def lcm(*numbers): return reduce(lcm_base, numbers, 1)#数列に対しての最小公倍数 n,m = map(int,input().split()) a = list(map(int,input().split())) b = [x//2 for x in a] c = 0 while True: if a[0]%2: for i in range(n): if a[i]%2 == 0: print(0) exit() break else: for i in range(n): if a[i]%2: print(0) exit() a[i]//=2 c += 1 least = lcm(*b) ans = ((m//least)+1)//2 print(ans)
abc150_d
11,457,700
import sys def gcd(x, y): if x % y == 0: return y return gcd(y, x % y) n, m = map(int, input().split()) a = list(map(int, input().split())) cur = a[0] for x in a[1:]: g = gcd(cur, x) if (cur // 2) % g != (x // 2) % g: print(0) sys.exit(0) else: cur = cur // g * x if cur > m * 2: print(0) sys.exit(0) print((m + cur // 2) // cur)
abc150_d
12,046,630
n, m = map(int, input().split()) a = list(map(int, input().split())) num1 = a[0] num2 = 0 while num1 % 2 == 0: num1 //= 2 num2 += 1 gc = 2 ** num2 b = [] for i in a: if i % gc != 0 or (i // gc) % 2 == 0: print(0) exit() else: b.append(i // gc) from fractions import gcd lcm = 1 for i in b: lcm = (lcm * i) // gcd(lcm, i) ans = m // (lcm * (gc // 2)) ans = (ans + 1) // 2 print(ans)
abc150_d
14,185,042
import sys import fractions def lcm(a, b): return abs(a*b) // fractions.gcd(a, b) n,m=map(int,input().split()) a=list(map(int,input().split())) c=2 while a[0]%c==0: c=c*2 c=c//2 fail=0 for i in range(n): if a[i]%c!=0: fail=1 if a[i]%(2*c)==0: fail=1 if fail==1: print(0) sys.exit() A=1 for i in range(n): A=lcm(A,a[i]) print(2*m//A-2*m//(2*A))
abc150_d
12,060,212
import sys inout = sys.stdin.readline def GCD(a, b): if b == 0: return a return GCD(b, a % b) def LCM(a, b): return a * b // GCD(a, b) n, m = map(int, input().split()) a = list(map(int, input().split())) lcm = 1 for i in a: i = i // 2 lcm = LCM(i, lcm) for i in a: i = i // 2 if (lcm // i) % 2 == 0: print(0) sys.exit(0) ans = ((m // lcm)+1) // 2 print(ans)
abc150_d
22,713,511
import math def main(): N, M = map(int, input().split()) A = list(map(lambda x: int(x) // 2, input().split())) Lcm = A[0] for i in range(1, N): Lcm = Lcm * A[i] // math.gcd(Lcm, A[i]) for a in A: if Lcm // a % 2 == 0: return print(0) Ans = 1 + (M - Lcm) // (Lcm * 2) print(Ans) if __name__ == '__main__': main()
abc150_d
12,251,741
def gcd(a, b): while a != 0: b = b%a a, b = b, a return b def lcm(a, b): return (a*b)//gcd(a,b) n, m = map(int, input().split()) a = list(map(int, input().split())) x = 1 for y in a: x = lcm(x, y//2) for y in a: if (x//(y//2)) % 2 == 0: print(0) exit() max_n = (m-x)//(2*x) print(max_n+1)
abc150_d
12,804,140
def gcd(a, b): while b: a, b = b, a%b return a def lcm(a, b): return a//gcd(a, b)*b def lcms(a): l = a[0] for num in a[1:]: l = lcm(l, num) return l n, m = map(int, input().split()) a = list(map(int, input().split())) # a2 = [num//2 for num in a] acount = [None]*n # aを2で割れる回数 anum = [None]*n # 割ったあとの残り(=奇数) for i,num in enumerate(a): c = 0 while num%2==0 and num>1: num //=2 c += 1 acount[i] = c anum[i] = num if all(item==acount[0] for item in acount): l = lcms(anum) num0 = l * (pow(2, (acount[0]-1))) span = num0*2 if m<num0: print(0) else: print(int((m-num0)//span + 1)) else: print(0)
abc150_d
15,696,309
import math def lcm(a,b): return (a*b)//math.gcd(a,b) def co(num): return format(num, 'b')[::-1].find('1') N,M=map(int,input().split()) L=list(map(int,input().split())) L2=[co(i) for i in L] if len(set(L2))!=1: print(0) exit() L=[i//2 for i in L] s=L[0] for i in range(N): s=lcm(s,L[i]) c=M//s print((c+1)//2)
abc150_d
9,416,687
from fractions import gcd #X=b_k*(2p+1) N,M=map(int,input().split()) b=[int(i)//2 for i in input().split()] def v2(n): tmp=n res=0 while(tmp>0): if tmp%2==0: tmp=tmp//2 res+=1 else: return res def lcm(x,y): return x*(y//gcd(x,y)) c=[v2(i) for i in b] if min(c)!=max(c): print(0) exit() L=1 for i in range(N): L=lcm(L,b[i]) print(M//L-M//(2*L))
abc150_d
22,750,850
import itertools import sys import math try: import numpy as np except ImportError: pass stdin = sys.stdin stderr = sys.stderr sys.setrecursionlimit(10 ** 6) def CP(cond, a, b): print(a if cond else b) def YESNO(cond): CP(cond, 'YES', 'NO') def YesNo(cond): CP(cond, 'Yes', 'No') def RS(): return sys.stdin.readline().strip() def RI(): return int(RS()) def RVI(): return [int(n) for n in RS().split()] def WVI(arr, sep=' ', **kwargs): print(sep.join([str(a) for a in arr]), **kwargs) (N, M) = RVI() A = [a//2 for a in RVI()] lcm = 1 for a in A: g = math.gcd(lcm, a) lcm *= a lcm //= g for a in A: if (lcm // a) % 2 == 0: print(0) exit(0) print((1 + (M // lcm)) // 2)
abc150_d
11,763,392
from fractions import gcd def lcm(a,b): return a*b//gcd(a,b) N,M = map(int,input().split()) A = [int(i) for i in input().split()] a = 0 b = A[0] while b % 2 == 0: a += 1 b = b//2 for i in range(1,N): if A[i] % (2**a) != 0 or A[i] % (2**(a+1)) == 0: print(0) exit() c = A[0] for i in range(N-1): c = lcm(c,A[i+1]) print((M+c//2)//c)
abc150_d
14,415,948
def gcd(x, y): while y > 0: r = x % y x = y y = r return x def lcm(x, y): return x // gcd(x, y) * y n, m = map(int, input().split()) a = list(map(int, input().split())) l = 1 for i in range(n): a[i] //= 2 l = lcm(a[i], l) flg = True for x in a: if (l // x) % 2 == 0: flg = False break if flg: print(m // l - m // (l * 2)) else: print(0)
abc150_d
15,827,914
from math import gcd N, M = map(int, input().split()) A = list(map(int, input().split())) lcm = 1 for a in A: lcm = lcm * a // gcd(lcm, a) if lcm > M*2: print(0) exit() for a in A: if lcm // a % 2 == 0: print(0) exit() ans = M // (lcm//2) - M // lcm print(ans)
abc150_d
15,081,281
from math import gcd def lcm(a, b): return a * b // gcd(a, b) n, m = map(int, input().split()) a = list(map(int, input().split())) l = [0] * n for i in range(n): tmp = a[i] while tmp % 2 == 0: tmp //= 2 l[i] += 1 if i > 0 and l[i] != l[i - 1]: print(0) exit(0) res = 1 for i in range(n): res = lcm(res, a[i] // 2) print(m // res - m // (res * 2))
abc150_d
15,311,118
import math import sys from functools import reduce N, M = map(int, input().split()) A = list(map(int, input().split())) for i in range(N): A[i] = A[i] // 2 def lcm_base(x, y): return (x * y) // math.gcd(x, y) def lcm_list(numbers): return reduce(lcm_base, numbers, 1) C = lcm_list(A) B = [0 for _ in range(N)] for i in range(N): B[i] = C // A[i] if B[i] % 2 == 0: print(0) sys.exit() print( (M // C + 1) // 2)
abc150_d
15,315,791
import sys import numpy as np def input(): return sys.stdin.readline().rstrip() def kosuu(x): re = [0,0] while x % 2 == 0: x = x//2 re[1]+=1 re[0]=x return re def main(): n,m=map(int, input().split()) a=list(map(int, input().split())) li = [kosuu(a[0])[0]] hantei = kosuu(a[0])[1] for i in a[1:]: hantei2 = kosuu(i) if hantei2[1] != hantei: print(0) break else: li.append(hantei2[0]) else: lc = np.lcm.reduce(li) print(((m//(lc*2**(hantei-1)))+1)//2) if __name__=='__main__': main()
abc150_d
15,347,602
from math import gcd def lcm(a, b): return a // gcd(a, b) * b N, M = map(int, input().split()) As = list(map(int, input().split())) rightmostbit = As[0] & -As[0] for A in As[1:]: if rightmostbit != A & -A: print(0) exit() lcm_of_half_As = 1 for A in As: lcm_of_half_As = lcm(lcm_of_half_As, A // 2) if lcm_of_half_As > M: break print((M // lcm_of_half_As + 1) // 2)
abc150_d
16,747,622
import sys from math import gcd sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return 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()) #空白なし N,M = MI() A = LI() x = sum(a % 2 == 0 for a in A) if x != N: print(0) exit() r = 0 while A[0] % 2 == 0: r += 1 A[0] //= 2 for i in range(1,N): if A[i] % (2**r) != 0 or (A[i]//(2**r)) % 2 == 0: print(0) exit() else: A[i] //= 2**r lcm = A[0] for i in range(1,N): lcm = (lcm*A[i])//gcd(lcm,A[i]) a = (lcm*2**r)//2 print(((M//a)+1)//2)
abc150_d
16,748,106
import sys from math import gcd def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり N,M = MI() A = LI() x = sum(a % 2 == 0 for a in A) if x != N: # 奇数が含まれたら駄目 print(0) exit() r = 0 while A[0] % 2 == 0: r += 1 A[0] //= 2 for i in range(1,N): if A[i] % (2**r) != 0 or (A[i]//(2**r)) % 2 == 0: # 2で割り切れる回数が異なるものがあったら駄目 print(0) exit() else: A[i] //= 2**r lcm = A[0] for i in range(1,N): lcm = (lcm*A[i])//gcd(lcm,A[i]) a = (lcm*2**r)//2 # a の奇数倍で、M 以下である整数の個数が答え print(((M//a)+1)//2)
abc150_d
18,008,063
#ABC150-D-Semi Common Multiple N,M = map(int,input().split()) a = list(map(int,input().split())) from math import gcd from functools import reduce g = reduce(gcd,a) if g%2 == 1: print(0) exit() a = [i//g for i in a] def lcm(x,y): return x*y//gcd(x,y) l = reduce(lcm,a) if l%2 == 0: print(0) exit() t = g*l//2 ans = (M//t+1)//2 print(ans)
abc150_d
18,008,058
#ABC150-D-Semi Common Multiple N,M = map(int,input().split()) a = list(map(int,input().split())) from math import gcd from functools import reduce g = reduce(gcd,a) if g%2 == 1: print(0) exit() a = [i//g for i in a] def lcm(x,y): return x*y//gcd(x,y) l = reduce(lcm,a) if l%2 == 0: print(0) exit() t = g*l//2 ans = (M//t+1)//2 print(ans)
abc150_d
18,008,150
#ABC150-D-Semi Common Multiple N,M,*a = map(int,open(0).read().split()) a = set(a) from math import gcd from functools import reduce g = reduce(gcd,a) if g%2 == 1: print(0) exit() a = {i//g for i in a} def lcm(x,y): return x*y//gcd(x,y) l = reduce(lcm,a) if l%2 == 0: print(0) exit() t = g*l//2 ans = (M//t+1)//2 print(ans)
abc150_d
18,008,289
#ABC150-D-Semi Common Multiple N,M,*a = map(int,open(0).read().split()) a = set(a) from math import gcd from functools import reduce g = reduce(gcd,a) a = {i//g for i in a} def lcm(x,y): return x*y//gcd(x,y) l = reduce(lcm,a) if g%2 == 1 or l%2 == 0: print(0) exit() print((2*M//g//l+1)//2)
abc150_d
10,798,219
import fractions from functools import reduce def lcm_base(x, y): return (x * y) // fractions.gcd(x, y) def lcm(*numbers): return reduce(lcm_base, numbers, 1) # 数列に対しての最小公倍数 n, m = map(int, input().split()) a = list(map(int, input().split())) b = [x // 2 for x in a] c = 0 while a[0] % (2 ** (c + 1)) == 0: c += 1 for x in a: if x % (2 ** c) != 0 or x % (2 ** (c + 1)) == 0: print(0) exit() lc = lcm(*b) ans = ((m // lc) + 1) // 2 print(ans)
abc150_d
18,008,105
#ABC150-D-Semi Common Multiple N,M = map(int,input().split()) a = set(map(int,input().split())) from math import gcd from functools import reduce g = reduce(gcd,a) if g%2 == 1: print(0) exit() a = [i//g for i in a] def lcm(x,y): return x*y//gcd(x,y) l = reduce(lcm,a) if l%2 == 0: print(0) exit() t = g*l//2 ans = (M//t+1)//2 print(ans)
abc150_d
18,222,444
n, m = map(int, input().split()) a = list(map(int, input().split())) num1 = a[0] num2 = 0 while num1 % 2 == 0: num1 //= 2 num2 += 1 gc = 2 ** num2 b = [] for i in a: if i % gc != 0 or (i // gc) % 2 == 0: print(0) exit() else: b.append(i // gc) from fractions import gcd lcm = 1 for i in b: lcm = (lcm * i) // gcd(lcm, i) ans = m // (lcm * (gc // 2)) ans = (ans + 1) // 2 print(ans)
abc150_d
17,419,279
def gcd(x, y): b = max(x, y) s = min(x, y) r = b % s while r != 0: b = s s = r r = b % s return s def lcm(x, y): return (x * y) // gcd(x,y) N, M = list(map(int, input().split())) a = list(map(int, input().split())) t = a[0] // 2 p = 0 while t % 2 == 0: p += 1 t //= 2 n = 1 for m in a: t = m // 2 q = 0 while t % 2 == 0: q += 1 t //= 2 if p != q: print(0) exit() n = lcm(n, m // 2) k = M // n ans = -(-k // 2) print(ans)
abc150_d
18,372,452
import math n,m=map(int,input().split()) a=list(map(int,input().split())) for i in range(n): a[i]//=2 ans=a[0] for i in range(n-1): ans=(ans*a[i+1])//math.gcd(ans,a[i+1]) yn=0 for i in range(n): if (ans//a[i])%2==0: yn=1 break if yn==1: print(0) else: if m<ans: print(0) else: m-=ans print(1+(m//(ans*2)))
abc150_d
17,390,253
from math import gcd n,m=map(int,input().split()) a=list(map(int,input().split())) a=list(set(a)) a.sort() n=len(a) for i in range(n): a[i]=a[i]//2 ans=1 for x in a: ans=ans*x//gcd(x,ans) if ans>m: print(0) else: if all((ans//a[i])%2==1 for i in range(n)): print(1+(m-ans)//(2*ans)) else: print(0)
abc150_d
18,409,843
from fractions import gcd n,m = map(int,input().split()) a = list(map(int,input().split())) b = [0]*n for i,x in enumerate(a): while x%2 == 0: b[i] += 1 x //=2 if min(b) != max(b): print(0) else: l = 1 for x in a: if l%(x//2) > 0: l = l*(x//2)//gcd(l,x//2) if l>m: break print((m//l+1)//2)
abc150_d
19,405,337
import sys import math from collections import defaultdict from collections import deque sys.setrecursionlimit(1000000) MOD = 10 ** 9 + 7 input = lambda: sys.stdin.readline().strip() NI = lambda: int(input()) NMI = lambda: map(int, input().split()) NLI = lambda: list(NMI()) SI = lambda: input() def main(): N, M = NMI() A = NLI() min_bits = set(a&(-a) for a in A) if len(min_bits) != 1: print(0) exit() lcm = 1 for a in A: g = math.gcd(a, lcm) lcm = a * lcm // g if lcm > 2 * M: print(0) exit() half = lcm // 2 print(M // half - M // lcm) if __name__ == "__main__": main()
abc150_d
18,008,325
#ABC150-D-Semi Common Multiple import sys sinput = sys.stdin.readline N,M = map(int,sinput().split()) a = set(map(int,sinput().split())) from math import gcd from functools import reduce g = reduce(gcd,a) a = {i//g for i in a} def lcm(x,y): return x*y//gcd(x,y) l = reduce(lcm,a) if g%2 == 1 or l%2 == 0: print(0) exit() print((2*M//g//l+1)//2)
abc150_d
18,008,124
#ABC150-D-Semi Common Multiple N,M = map(int,input().split()) a = set(map(int,input().split())) from math import gcd from functools import reduce g = reduce(gcd,a) if g%2 == 1: print(0) exit() a = {i//g for i in a} def lcm(x,y): return x*y//gcd(x,y) l = reduce(lcm,a) if l%2 == 0: print(0) exit() t = g*l//2 ans = (M//t+1)//2 print(ans)
abc150_d
16,407,206
from math import gcd import sys N, M = map(int, input().split()) A = list(map(int, input().split())) lcm = 1 for a in A: gcd_ = gcd(lcm, a//2) lcm = lcm * (a // 2 // gcd_) for a in A: if (lcm // (a // 2)) % 2 == 0: print(0) sys.exit() print(M // lcm - M // (2 * lcm))
abc150_d
22,899,313
import numpy as np from sys import stdin n, m, *indata = map(int, stdin.read().split()) a = [] for i in range(n): a.append(indata[i] // 2) x = np.lcm.reduce(a) if x > m: print("{}".format(0)) exit() for i in range(n): if (x // a[i]) % 2 == 0: print("{}".format(0)) exit() ans = ((m // x) + 1) // 2 print("{}".format(ans))
abc150_d
9,414,311
import fractions import math n,m = map(int,input().split()) l = list(map(int,input().split())) count = 0 while True: if l[0] % 2 == 0: l[0] //= 2 count += 1 else: break for i in range(1,n): l[i] //= 2**count if l[i] % 1 != 0 or l[i] % 2 == 0: print(0) exit() ans = l[0] for i in range(1,n): ans = ans * l[i] //fractions.gcd(ans,l[i]) ans1 = (m//2**(count-1))//ans if ans1 % 2 == 0: print(ans1//2) else: print(ans1//2+1)
abc150_d
20,812,343
from math import gcd n,m = map(int,input().split()) a = list(map(int,input().split())) g = 0 for i in a: g = gcd(g,i) for i in a: if i//g%2 == 0: print(0) exit() lcm = 1 for i in a: gtmp = gcd(i,lcm) lcm = lcm*i//gtmp if lcm > m*10: print(0) exit() lcm //= 2 print((m//lcm+1)//2)
abc150_d
43,748,795
def inv_gcd(a, b): a %= b if a == 0: return b, 0 # 初期状態 s, t = b, a m0, m1 = 0, 1 while t: # 遷移の準備 u = s // t # 遷移 s -= t * u m0 -= m1 * u # swap s, t = t, s m0, m1 = m1, m0 if m0 < 0: m0 += b // s return s, m0 def crt(r, m): assert len(r) == len(m) n = len(r) r0, m0 = 0, 1 # 初期値 x = 0 (mod 1) for i in range(n): assert m[i] >= 1 #r1, m1は遷移に使う値 r1, m1 = r[i] % m[i], m[i] #m0がm1以上になるようにする。 if m0 < m1: r0, r1 = r1, r0 m0, m1 = m1, m0 # m0がm1の倍数のとき gcdはm1、lcmはm0 # 解が存在すれば何も変わらないので以降の手順はスキップ if m0 % m1 == 0: if r0 % m1 != r1: return [0, 0] continue # 拡張ユークリッドの互除法によりgcd(m0, m1)と m0 * im = gcd (mod m1) を満たす imを求める g, im = inv_gcd(m0, m1) # 解の存在条件の確認 if (r1 - r0) % g: return [0, 0] """ r0, m0の遷移 コメントアウト部分はACLでの実装 C++なのでlong longを超えないようにしている C++ はlcm(m0, m1)で割った余りが負になり得る """ # u1 = m1 // g # x = (r1 - r0) // g % u1 * im % u1 # r0 += x * m0 # m0 *= u1 u1 = m0 * m1 // g r0 += (r1 - r0) // g * m0 * im % u1 m0 = u1 #if r0 < 0: r0 += m0 return [r0, m0] N,M=map(int,input().split()) A=[int(x) for x in input().split()] B=[a//2 for a in A] p,q=crt(B, A) if q==0: print(0) else: u=M//q if u*q+p<=M: u+=1 print(u)
abc150_d
22,948,964
from math import * from copy import copy n,m = map(int,input().split()) b = list(map(int,input().split())) a = copy(b) x = -1 for i in range(n): cnt = 0 while a[i]%2 == 0: a[i] //= 2 cnt += 1 if x != -1 and cnt != x: print(0) exit() elif x == -1: x = cnt l = 1 for i in b: i //= 2 g = gcd(l,i) l = l*i // g print(m//l - m//(2*l))
abc150_d
9,405,774
from fractions import gcd def lcm(p,q): return p*q//gcd(p,q) n,m = map(int, input().split()) a = list(map(int, input().split())) x = 1 for i in range(n): a[i] = a[i]//2 x = lcm(x,a[i]) if x>m: print(0) exit() for i in range(n): if (x//a[i])%2==0: print(0) exit() p = m//x if p%2==0: ans = p//2 else: ans = p//2 +1 print(ans)
abc150_d
28,504,771
from math import gcd n,m = map(int,input().split()) a = list(map(int,input().split())) b = [a[i]//2 for i in range(n)] scm = 1 for i in range(n): scm = scm*b[i]//gcd(scm,b[i]) flag = True for i in range(n): if (scm//b[i])%2 == 0:flag = False if flag: print((m-scm)//(2*scm)+1) else: print(0)
abc150_d
28,504,731
from math import gcd n,m = map(int,input().split()) a = list(map(int,input().split())) b = [a[i]//2 for i in range(n)] scm = 1 for i in range(n): scm = scm*b[i]//gcd(scm,b[i]) flag = True for i in range(n): if (scm//b[i])%2 == 0:flag = False if flag: print((m-scm)//(2*scm)+1) else: print(0)
abc150_d
21,047,518
import math N, M = map(int, input().split()) A = list(map(int, input().split())) A = list(map(lambda x: x // 2, A)) S = set() for i in range(N): cnt = 0 val = A[i] while val % 2 == 0: val //= 2 cnt += 1 S.add(cnt) if len(S) != 1: print(0) else: lcm = 1 for i in range(N): lcm = lcm * A[i] // math.gcd(lcm, A[i]) print((M - lcm) // (2 * lcm) + 1)
abc150_d
9,407,501
def ng(a): b = [] for x in a: two = 0 while x%2 == 0: x //= 2 two += 1 b.append(two) return sum(b) != b[0]*len(b) def gcd(a, b): return a if b == 0 else gcd(b, a%b) def lcm(a, b): return a//gcd(a,b)*b def fail(): print(0) exit(0) n, m = map(int, input().split()) a = [int(x)//2 for x in input().split()] if ng(a): fail() lc = 1 for x in a: lc = lcm(lc, x) if lc > m: fail() ret = 1 m -= lc ret += m//(2*lc) print(ret)
abc150_d
23,102,081
import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) sys.setrecursionlimit(10**7) yes = lambda :print("yes");Yes = lambda :print("Yes") no = lambda :print("no");No = lambda :print("No") ####################################################################### n,m = na() a = na() z = 1 import math def lca(x,y): return x*y//math.gcd(x,y) for i in range(n): z = lca(z,a[i]//2) if z>m: print(0) exit() for i in range(n): if (z//(a[i]//2))%2==0: print(0) exit() print((m//z + 1)//2)
abc150_d
22,354,334
N, M = map(int,input().split()) A = list(map(int,input().split())) cnt = 0 a = A[0] while not a&1: cnt += 1 a//=2 for a in A: tmp = 0 while not a&1: tmp += 1 a//=2 if tmp != cnt: print(0) exit() from math import gcd def lcm(x,y): l = x*y//gcd(x,y) if l > M: print(0) exit() return l from functools import reduce LCM = reduce(lcm,[A[i]//2 for i in range(N)]) res = M//LCM print(res//2+(res&1))
abc150_d
33,554,530
import math def gcd(x, y): return math.gcd(x,y) def lcm(x, y): return (x * y) // math.gcd(x,y) N, M = list(map(int, input().split())) a = list(map(int, input().split())) c = 0 n = a[0] while not n % 2: c += 1 n //= 2 s = 1 for n in a: s = lcm(s, n // 2) t = 0 while not n % 2: t += 1 n //= 2 if t != c: print(0) exit() n = (M + s) // (2 * s) print(n)
abc150_d
28,669,191
from math import gcd n,m=map(int,input().split()) a=list(map(int,input().split())) for i in range(n): a[i]//=2 k=a[0] tmp=0 curr=1 while k%2==0: k//=2 tmp+=1 for i in range(n): k=a[i] tmp2=0 while k%2==0: k//=2 tmp2+=1 if tmp2!=tmp: print(0) exit() curr=(a[i]*curr)//gcd(a[i],curr) print((m//curr+1)//2)
abc150_d
28,669,186
n, m = map(int, input().split()) a = list(map(int, input().split())) for i in range(n): a[i] //= 2 from math import gcd l = 1 for ai in a: l = l * ai // gcd(l, ai) if any(l // ai % 2 == 0 for ai in a): print(0) exit() ans = len(range(l, m + 1, l * 2)) print(ans)
abc150_d
19,523,836
import math N,M=map(int,input().split()) a=list(map(int,input().split())) X=set() for i in range(N): n=0 while a[i]%2==0: a[i]//=2 n+=1 X.add(n) if len(X)!=1: print(0) else: A=a[0] for i in a[1:]: A=(A*i)//math.gcd(A,i) A*=2**(n-1) print(M//A-M//(2*A))

No dataset card yet

New: Create and edit this dataset card directly on the website!

Contribute a Dataset Card
Downloads last month
0
Add dataset card