Problem:


Score : 400 points

Problem Statement

Given are positive integers A and B.

Let us choose some number of positive common divisors of A and B.

Here, any two of the chosen divisors must be coprime.

At most, how many divisors can we choose?

Definition of common divisor

An integer d is said to be a common divisor of integers x and y when d divides both x and y.

Definition of being coprime

Integers x and y are said to be coprime when x and y have no positive common divisors other than 1.

Definition of dividing

An integer x is said to divide another integer y when there exists an integer \alpha such that y = \alpha x.

Constraints

All values in input are integers.

1 \leq A, B \leq 10^{12}

Input

Input is given from Standard Input in the following format:

A B

Output

Print the maximum number of divisors that can be chosen to satisfy the condition.

Sample Input 1

12 18

Sample Output 1

3

12 and 18 have the following positive common divisors: 1, 2, 3, and 6.

1 and 2 are coprime, 2 and 3 are coprime, and 3 and 1 are coprime, so we can choose 1, 2, and 3, which achieve the maximum result.

Sample Input 2

420 660

Sample Output 2

4

Sample Input 3

1 2019

Sample Output 3

1

1 and 2019 have no positive common divisors other than 1.



Sample input:
12 18


Sample output:
3

Submission status: Time Limit Exceeded

Solution code:
a,b = [int(i) for i in input().split()]
def my_gcd(a,b):
    if b == 0:
        return a
    return my_gcd(b,a%b)
def is_prime(a,d):
    aux = int(a**0.5)
    for i in d[:-1]:
        if not a%i:
            return 0
        if i>aux:
            break
    return 1
c  = my_gcd(a,b)
s = 1
p = 3
d = [2]#,3,5,7,11,17,19,23,29,31,37,41,43]
if not c%2:
    s += 1
    while not c%2:
        c = c//2
while c!=1:
    if is_prime(p,d):
        d.append(p)
        if not c%p:
            while not c%p:
                c = c//p
            s += 1
    p += 2
print(s)

Submission status: Time Limit Exceeded

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

def make_divisors(n):
	divisors = set()
	for i in range(1, int(n**0.5)+1):
		if n % i == 0:
			divisors.add(i)
			if i != n // i:
				divisors.add(n//i)
	return divisors
	
A = make_divisors(a)
B = make_divisors(b)
S = A & B
cnt = 0
for _ in S:
	mk = make_divisors(_)
	MK = mk & S
	if len(MK) <= 2:
		cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
a,b = [int(i) for i in input().split()]
def my_gcd(a,b):
    if b == 0:
        return a
    return my_gcd(b,a%b)
def is_prime(a):
    for i in range(2,a):
        if not a%i:
            return 0
    return 1
c  = my_gcd(a,b)
s = 1
p = 2
while c!=1:
    if is_prime(p) and not c%p:
        while not c%p:
            c = c//p
        s += 1
    p += 1
print(s)

Submission status: Time Limit Exceeded

Solution code:
a,b = [int(i) for i in input().split()]
def my_gcd(a,b):
    if b == 0:
        return a
    return my_gcd(b,a%b)
def is_prime(a):
    for i in range(2,a):
        if not a%i:
            return 0
    return 1
c  = my_gcd(a,b)
s = 1
for i in range(2,c+1):
    if is_prime(i) and not c%i:
        c = c//i
        s += 1
    if c==1:
        break
print(s)

Submission status: Time Limit Exceeded

Solution code:
a,b = [int(i) for i in input().split()]
def check_arr(c,num):
    for i in c:
        if i<num and not num%i:
            return 0
        elif i>=num:
            return 1
    return 1

c = [i for i in range(2,a if b>a else b) if not (a%i or b%i)]
d = [j for j in c if check_arr(c,j)]
print(len(d) + 1)

Submission status: Time Limit Exceeded

Solution code:
A, B = map(int,input().split())
def gcd(a,b):
    if a < b:
        a,b = b,a
    if b == 0: return a
    r = a % b
    return gcd(b,r)

L = [1]

g = gcd(A, B)
i = 2
while g > 1:
    if g % i == 0:
        if L[-1] != i:
            L.append(i)
        g /= i
    else:
        i += 1
print(len(L))

Submission status: Time Limit Exceeded

Solution code:
A, B = map(int,input().split())
def gcd(a,b):
    if a < b:
        a,b = b,a
    if b == 0: return a
    r = a % b
    return gcd(b,r)

L = []

g = gcd(A, B)
i = 2
while g > 1:
    if g % i == 0:
        L.append(i)
        g /= i
    else:
        i += 1
def counter(array):
    from collections import Counter
    return list(Counter(array).most_common())
c = counter(L)
print(len(c) + 1)

Submission status: Time Limit Exceeded

Solution code:
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


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

import fractions

n = fractions.gcd(A, B)
divisors = make_divisors(n)
N = len(divisors)

count = 0
flag = [0] * N
for i in range(1, N - 1):
    for j in range(i + 1, N):
        if divisors[j] % divisors[i] == 0:
            if flag[j] == 0:
                count += 1
                flag[j] = 1

print(N - count)

Submission status: Time Limit Exceeded

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

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


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

n = gcd(A, B)
divisors = make_divisors(n)
N = len(divisors)

count = 0
flag = [0] * N
for i in range(1, N - 1):
    for j in range(i + 1, N):
        if divisors[j] % divisors[i] == 0:
            if flag[j] == 0:
                count += 1
                flag[j] = 1

print(N - count)

Submission status: Time Limit Exceeded

Solution code:
A, B = [int(i) for i in input().split()]

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

def cd (x, y):
    a = gcd(x, y)

    cd_list = []
    for i in range(1, a + 1):
        if a % i == 0:
            cd_list.append(i)

    return cd_list

cd_list = cd(A, B)
f_list = [0] * len(cd_list)
for i in range(1, len(cd_list) - 1):
    for j in range(i + 1, len(cd_list)):
        if cd_list[j] % cd_list[i] == 0:
            f_list[j] = 1
    
count = 0
for i in range(len(f_list)):
    if f_list[i] == 0:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
A,B=map(int,input().split())

def gcd (a,b):
    temp=[]
    M=max(a,b)
    m=min(a,b)
    for i in range(-int(-M**0.5//1)):
        if M%(i+1)==0:
            if m%(i+1)==0:
                temp.append(i+1)
            if m%(M//(i+1))==0:
                temp.append(M//(i+1))
    return temp

koyaku=max(gcd(A,B))

count=0
for i in range(2,koyaku+1):
    judge=True
    while koyaku%i==0 and koyaku!=1:
        koyaku//=i
        if judge==True:
            count+=1
            judge=False
print(count+1)

Submission status: Time Limit Exceeded

Solution code:
import fractions
A,B=map(int,input().split())
G=fractions.gcd(A,B)
S={1,G}
for n in range(1,G+1):
  if G%n==0:
    S=S|{n}
for p in S:
  t=2
  while t<=int(p**(1/2)):
    if p%t==0:
      S=S-{p}
      break
    t+=1
print(len(S))

Submission status: Time Limit Exceeded

Solution code:
import fractions
A,B=map(int,input().split())
G=fractions.gcd(A,B)
S={1}
for n in range(1,G+1):
  if G%n==0:
    S=S|{n}
for p in S:
  t=2
  while t<int(p):
    if p%t==0:
      S=S-{p}
      break
    t+=1
print(len(S))

Submission status: Time Limit Exceeded

Solution code:
import math

def get_spf(n):
	ans = [i for i in range(n + 1)]

	for p in range(2, n + 1):
		if ans[p] == p:
			for i in range(p**2, n + 1, p):
				if ans[i] == i:
					ans[i] = p

	return ans

def get_pf(n, spf):
	ans = []

	while n > 1:
		ans.append(spf[n])
		n = int(n / spf[n])

	return ans

if __name__ == "__main__":
	line = input().split(" ")

	a, b = int(line[0]), int(line[1])

	# spf = get_spf(max(math.ceil(math.sqrt(a)), math.ceil(math.sqrt(b))))
	spf = get_spf(max(a, b))

	primes_a = set(get_pf(a, spf))
	primes_b = set(get_pf(b, spf))

	ans = []
	for e in primes_a:
		if e in primes_b:
			ans.append(e)

	print(1 + len(ans))

Submission status: Time Limit Exceeded

Solution code:
import math

a, b = map(int, input().split())
fa = []
fb = []

tmp = a//2 + 1
for i in range(2,tmp):
    while a % i == 0:
        a //= i
        fa.append(i)
fa.append(a)

tmp = b//2 + 1
for i in range(2,tmp):
    while b % i == 0:
        b //= i
        fb.append(i)
fb.append(b)

print(len(list(set(fa) & set(fb))))

Submission status: Time Limit Exceeded

Solution code:
[N, M] = list(map(float, input().split()))

def so_func(x):
    a = set()
    for i in range(1, int(x+1)):
        if ((x)/i).is_integer():
            a.add(i)
    return a

answer = list(so_func(N) & so_func(M))
answer.sort()
b = set()
for i in reversed(range(1, len(answer))):
    for j in range(1, i):
        if float(answer[i]/answer[j]).is_integer():
            b.add(answer[i])
answer = set(answer) - b
print(len(answer))

Submission status: Time Limit Exceeded

Solution code:
import math

def is_prime(n):
    for p in range(2, int(math.sqrt(n)) + 1):
        if n % p == 0:
            return False
    return True

A, B = map(int, input().split())
N = min(A, B) // 2
lst = [1]
for n in  range(2, N + 1):
    if A % n == 0 and B % n == 0:
        lst.append(n)

ret = 1
for n in lst[1:]:
    if is_prime(n):
        ret += 1
print(ret)

Submission status: Time Limit Exceeded

Solution code:
a, b = map(int,input().split())
if a < b:
    buf = a
    a = b
    b = buf
while b != 0:
    a, b = b, a % b
gcd = a
count = 1
if gcd % 2 == 0:
    count += 1
    while gcd % 2 == 0:
        gcd = int(gcd / 2)
if gcd % 3 == 0:
    count += 1
    while gcd % 2 == 0:
        gcd = int(gcd / 3)


def hantei(num):
    flag = True
    for i in range(2, int(num**0.5) + 1):
        if num % i == 0:
            flag = False
    return flag


if gcd < 5:
    print(count)
else:
    for i in range(5, gcd + 1, 2):
        if gcd % i == 0 and hantei(i) == True:
            count += 1
            while gcd % i == 0:
                gcd = int(gcd / i)
            if gcd < i+2 :
                print(count)
                exit()
    print(count)

Submission status: Time Limit Exceeded

Solution code:
a, b = map(int,input().split())
if a < b:
    buf = a
    a = b
    b = buf
while b != 0:
    a, b = b, a % b
gcd = a
count = 1
if gcd % 2 == 0:
    count += 1
    gcd = int(gcd / 2)
if gcd % 3 == 0:
    count += 1
    gcd = int(gcd / 3)


def hantei(num):
    flag = True
    for i in range(2, int(num**0.5) + 1):
        if num % i == 0:
            flag = False
    return flag


if gcd < 5:
    print(count)
else:
    for i in range(5, gcd + 1, 2):
        if gcd % i == 0 and hantei(i) == True:
            count += 1
            gcd = int(gcd / i)
    print(count)

Submission status: Time Limit Exceeded

Solution code:
import math

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

def gcd(x, y):
  z = x % y
  if z == 0:
    return y
  else:
    return gcd(y, z)
  
def common_divisors(x, y):
  gcd1 = 0
  if x == y:
    gcd1 = x
  elif x > y:
    gcd1 = gcd(x, y)
  else:
    gcd1 = gcd(y, x)
    
  divisors = []
  for i in range(1, gcd1):
    if x % i == 0 and y % i == 0:
      divisors.append(i)
  divisors.append(gcd1)
  return divisors

def make_divisors(n):
  divisors = [] 
  for i in range(2, int(math.sqrt(n)) + 1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n // i)
  return divisors

divisors = common_divisors(a, b)
divisors_set = frozenset(divisors)

res = []

for n in divisors:
  if n == 1 or n == 2 or n == 3:
    res.append(n)
  elif n % 2 == 0:
    continue
  else:
    dvs = set(make_divisors(n))
    if len(dvs) == 0 or not dvs <= divisors_set:
      res.append(n)

print("{}".format(len(res)))

Submission status: Time Limit Exceeded

Solution code:
a, b = map(int,input().split())
if a < b:
    buf = a
    a = b
    b = buf
while b != 0:
    a, b = b, a % b
gcd = a
count = 1
if gcd % 2 == 0:
    count += 1
    gcd = int(gcd / 2)
if gcd % 3 == 0:
    count += 1
    gcd = int(gcd / 3)


def hantei(num):
    flag = True
    for i in range(2, int(num**0.5) + 1):
        if num % i == 0:
            flag = False
    return flag


if gcd < 5:
    print(count)
else:
    for i in range(5, gcd + 1):
        if gcd % i == 0 and hantei(i) == True:
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
a, b = map(int,input().split())
if a < b:
    buf = a
    a = b
    b = buf
while b != 0:
    a, b = b, a % b
gcd = a
count = 1
if gcd % 2 == 0:
    count += 1
if gcd % 3 == 0:
    count += 1


def hantei(num):
    flag = True
    for i in range(2, int(num**0.5+1)):
        if num % i == 0:
            flag = False
    return flag


if gcd < 5:
    print(count)
else:
    for i in range(5, gcd + 1):
        if gcd % i == 0 and hantei(i) == True:
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
def find_prime(num):
    p  = round(num**0.5)
    if num == 2:
        return num
    if num%2 == 0:
        return None
    for i in range(3, p+1, 2):
        if num%i == 0:
            return None
    return num

A, B = tuple(map(int, input().split()))
p = round((max(A, B)**0.5))
A_prime = find_prime(A)
B_prime = find_prime(B)
count = 1
if A==B and A_prime:
    if A == 1:
        print(1)
    else:
        print(2)
elif A_prime or B_prime:
    print(1)
else:
    for i in range(2, min(A, B)):
        if A%i == 0 and B%i == 0:
            if find_prime(i):
                count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
A,B=raw_input().split()
a=int(A)
b=int(B)

def gen_prime_number(n):
    c = 1
    l = []
    while True:
        c += 1
        if c > n:
            return
        found = False
        for i in l:
            if c % i == 0:
                found=True
                break
        if not found:
            l.append(c)
            yield c

def get_divisors_list(n):
    l = [1]
    for i in gen_prime_number(n/2):
        if n%i == 0:
            l.append(i)
    return l

ap = get_divisors_list(a)
bp = get_divisors_list(b)

print len([ i for i in ap if i in bp ])

Submission status: Time Limit Exceeded

Solution code:
a,b = map(int,input().split())
seta = []
setb = []
for i in range(1,a+1):
    if a % i == 0:
        seta.append(i)
for i in range(1,b+1):
    if b % i == 0:
        setb.append(i)
setab = list(set(seta) & set(setb))

for i in reversed(setab):
    for j in setab:
        if i <= j:
            break
        if j != 1 and i % j == 0:
            setab.remove(i)
            break

print(len(setab))

Submission status: Time Limit Exceeded

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

def get_cd(x1,x2):
    cd=[]
    for i in range(1,min(x1,x2)+1):
        if x1%i==0 and x2%i==0:
            cd.append(i)
    return cd

cd_AB=get_cd(A,B)

for j in range (0,len(cd_AB)-1):
    for k in range(j+1,len(cd_AB)):
        if(cd_AB[k]!=0):
            if(len(get_cd(cd_AB[j],cd_AB[k]))>1):
                cd_AB[k]=0

print(len(cd_AB)-cd_AB.count(0))

Submission status: Time Limit Exceeded

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

def get_cd(x1,x2):
    cd=[]
    for i in range(1,min(x1,x2)+1):
        if x1%i==0 and x2%i==0:
            cd.append(i)
    return cd

cd_AB=get_cd(A,B)

for j in range (0,len(cd_AB)-1):
    for k in range(j+1,len(cd_AB)):
            if(len(get_cd(cd_AB[j],cd_AB[k]))>1):
                cd_AB[k]=0

print(len(cd_AB)-cd_AB.count(0))

Submission status: Time Limit Exceeded

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

def get_cd(x1,x2):
    cd=[]
    for i in range(1,min(x1,x2)+1):
        if x1%i==0 and x2%i==0:
            cd.append(i)
    return cd

cd_AB=get_cd(A,B)


for j in range (0,len(cd_AB)-1):
    for k in range(j+1,len(cd_AB)):
        if(len(get_cd(cd_AB[j],cd_AB[k]))>1):
            cd_AB[k]=0

print(len(cd_AB)-cd_AB.count(0))

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

def is_prime(n):
  if n == 2 or n == 3: return True
  if n < 2 or n%2 == 0: return False
  if n < 9: return True
  if n%3 == 0: return False
  r = int(n**0.5)
  f = 5
  while f <= r:
    if n%f == 0: return False
    if n%(f+2) == 0: return False
    f +=6
  return True  

a, b = (int(x) for x in input().split())
val = gcd(a, b)
number_of_primes = 0
if val == 1:
    ans = 1
else:
    for i in range(val-1):
        if a % val == 0 and b % val == 0 and is_prime(val):
            number_of_primes += 1
        val -= 1
    ans = number_of_primes +1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
A, B = map(int, input().split())
def get_cds(a, b):
    low = min(a, b)
    high = max(a, b)
#     low_sqrt = math.sqrt(low)
#     high_sqrt = math.sqrt(high)
    i = 2
    candidates = []
    while(i <= low):
        if(low % i == 0):
            candidates.append(i)
        i += 1
    cds = []
    for j in candidates:
        if(high % j == 0):
            cds.append(j)
    cds2 = []
    while(len(cds) > 0):
        e = cds.pop(0)
        for ee in cds[:]:
            if(ee % e == 0):
                cds.remove(ee)
        cds2.append(e)
    return cds2

print(len(get_cds(A, B)) + 1)

Submission status: Time Limit Exceeded

Solution code:

def primenum_checker(n):
  for i in range(2,n):
    if n % i == 0:
      break
  return 1

def Prime_factorization(m):
  A = []
  for i in range(2,m+1):
    while m % i == 0:
      A.append(i)
      m = m / i
  return A

def intersect_list(lst1, lst2):
    arr = []
    lst = lst1.copy()
    for element in lst2:
        try:
            lst.remove(element)
        except ValueError:
            pass
        else:
            arr.append(element)
    return arr

i = list(map(int, input().split()))
a = i[0]
b = i[1]

A = Prime_factorization(a)
B = Prime_factorization(b)
candidate = intersect_list(A,B)

pcd = []
i_prev = -5
for i in candidate:
  if primenum_checker(i) == 1 and i != i_prev:
    pcd.append(i)
    i_prev = i
print(1 + len(pcd))

Submission status: Time Limit Exceeded

Solution code:
def get_common_divisor_list(a,b):
	cd_list = []
	for i in range(1,min(a,b)+1):
		if a%i == 0 and b%i == 0:
			cd_list.append(i)
	return cd_list

def is_coprime(a,b):
	cd_list = get_common_divisor_list(a,b)
	if len(cd_list) == 1 and 1 in cd_list :
		return True
	return False

from math import sqrt
def is_prime(n):
	if n==1:
		return False
	for k in range(2,int(sqrt(n))+1):
		if n%k == 0:
			return False
	return True

def main():
	A,B = map(int,input().split())
	cds = get_common_divisor_list(A,B)
	res = []
	for cd in cds :
		if cd == 1 :
			res.append(1)
			continue
		if is_prime(cd):
			res.append(cd)
	print(len(res))
main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import fractions
#nの素数判定
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True
    
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []
    time = 0
    while True:
        prime = min(A)
        if prime > math.sqrt(limit):
            break
        P.append(prime)
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
    for a in A:
        P.append(a)
    return len(P)

def cf(x1,x2):
    cf=[]
    for i in range(2,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

# 2
input_line = input()
array = list(map(int,input_line.split()))
A, B = array[0],array[1]
min_num = min(A,B)

common_factors = []



f=fractions.gcd(A,B)
f2=A*B//f
# print(f,f2)
common_factors = cf(f,f2)

# for i in range(1,min_num+1,1):
#     if(A % i== 0 and B % i== 0):
#         common_factors.append(i)


common_factors_prime = [common_factors[i] for i in range(len(common_factors)) if is_prime(common_factors[i])]

print(len(common_factors_prime) + 1)

Submission status: Time Limit Exceeded

Solution code:
import sys
#nの素数判定
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True
    
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []
    time = 0
    while True:
        prime = min(A)
        if prime > math.sqrt(limit):
            break
        P.append(prime)
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
    for a in A:
        P.append(a)
    return len(P)

def cf(x1,x2):
    cf=[]
    for i in range(2,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

# 2
input_line = input()
array = list(map(int,input_line.split()))
A, B = array[0],array[1]
min_num = min(A,B)

common_factors = []
common_factors = cf(A,B)

# for i in range(1,min_num+1,1):
#     if(A % i== 0 and B % i== 0):
#         common_factors.append(i)


common_factors_prime = [common_factors[i] for i in range(len(common_factors)) if is_prime(common_factors[i])]

print(len(common_factors_prime) + 1)

Submission status: Time Limit Exceeded

Solution code:
import sys
#nの素数判定
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True
    
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []
    time = 0
    while True:
        prime = min(A)
        if prime > math.sqrt(limit):
            break
        P.append(prime)
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
    for a in A:
        P.append(a)
    return len(P)

def cf(x1,x2):
    cf=[]
    for i in range(2,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

# 2
input_line = input()
array = list(map(int,input_line.split()))
A, B = array[0],array[1]
min_num = min(A,B)

common_factors = []
# common_factors = cf(A,B)

for i in range(1,min_num+1,1):
    if(A % i== 0 and B % i== 0):
        common_factors.append(i)


common_factors_prime = [common_factors[i] for i in range(len(common_factors)) if is_prime(common_factors[i])]

print(len(common_factors_prime) + 1)

Submission status: Time Limit Exceeded

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


def make_divisors(n):
    divisors = []
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.append(n)
    return divisors


def pri(n):
    if n == 1:
        return 1

    for i in range(2, int(n/2 + 1)):
        if n % i == 0:
            return 0

    else:
        return 1


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

C = gcd(A, B)

d = make_divisors(C)
d.append(1)
d = list(set(d))

cnt = 0
for i in d:
    cnt += pri(i)

print(cnt)

Submission status: Time Limit Exceeded

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

def main():
  a,b = map(int, input().split())
  g = gcd(a,b)
  N = int(g*0.5)
  ans = 1
  for i in range(2, N+1):
    flag = 0
    while(g%i==0):
      g /= i
      flag = 1
    ans += flag
  if g != 1:
    ans += 1
  print(ans)

main()

Submission status: Time Limit Exceeded

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

a,b = map(int, input().split())
g = gcd(a,b)
N = int(g*0.5)
ans = 1
for i in range(2, N+1):
  flag = 0
  while(g%i==0):
    g /= i
    flag = 1
  ans += flag
if g != 1:
  ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# from math import gcd
from fractions import gcd

def cd(x):
    return [i for i in range(1, x+1) if x%i==0]

def prime(x):
    for i in range(2, int(x**0.5)+1):
        if x%i == 0:
            return False
    return True

def main():
    a, b = map(int, input().split())
    c = gcd(a, b) #最小公倍数
    c = cd(c) #最小公倍数の約数のリスト
    #素数判定
    # ans = []
    ans = 0
    for i in c:
        if i == 1 or i==2:
            # ans.append(i)
            ans += 1
        elif prime(i):
            # ans.append(i)
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def factorize(a):
    x=2
    ret=[]
    while x<=a:
        while a%x==0:
            a//=x
            ret.append(x)
        x+=1
    return ret

def gcd(a,b):
    tmp=a
    a=max(a,b)
    b=min(tmp,b)
    if(a%b==0):
        return b
    return gcd(b,a%b)

a,b=map(int,input().split())
print(len(set(factorize(gcd(a,b))))+1)

Submission status: Time Limit Exceeded

Solution code:
def factorize(a):
    x=2
    ret=[]
    while x<=a:
        while a%x==0:
            a//=x
            ret.append(x)
        x+=1
    return ret
a,b=map(int,input().split())
set_fac_a=set(factorize(a))
set_fac_b=set(factorize(b))
set_ans=set_fac_a & set_fac_b
print(len(set_ans)+1)

Submission status: Time Limit Exceeded

Solution code:



def gcd(x,y):
  if(y!=0):
    return gcd(y,x%y)
  else:
    return x


I=[int(c) for c in input().split()]
a=max(I)
b=min(I)

g=gcd(a,b)

count=1

i=2
while(g!=1):
  if(g%i==0):
    count+=1
  while(g%i==0):
    g/=i
  i+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
import math
A, B = [int(x) for x in input().split()]
N = gcd(A, B)
p_list = set({})
for i in range(1, N+1):
    if (N != (N//i * i)):
        continue
    if (i == 1):
        p_list.add(i)
    else:
        is_prime = True
        for p in p_list:
            if (p != 1 and i == (i//p * p)):
                is_prime = False
        if (is_prime):
            p_list.add(i)
print(len(p_list))

Submission status: Time Limit Exceeded

Solution code:
A,B = (map(int, input().split()))
prime_NA,prime_NB = [],[]
cntA,cntB=0,0
minAB = min([A,B])
for i in range(minAB):
    if A%(i+1)==0:
        for j in range(i+1):
            if (i+1)%(j+1)==0:
                cntA+=1
        if cntA<=2:
            prime_NA.append(i+1)
        cntA = 0
    if B%(i+1)==0:
        for j in range(i+1):
            if (i+1)%(j+1)==0:
                cntB+=1
        if cntB<=2:
            prime_NB.append(i+1)
        cntB = 0
print(len(set(prime_NA)&set(prime_NB)))

Submission status: Time Limit Exceeded

Solution code:
def calcDiv(n):
    d_list = [1, n]
    for i in range(2, int(n**(1/2))+1):
        if n%i == 0:
            d_list.append(i)
            d_list.append(int(n/i))
    return d_list


def isPrime(n):
    for i in range(2, n):
        if n % i == 0:
            return False
    return True


if __name__ == "__main__":    
    a, b = map(int, input().split())
    a_list = calcDiv(a)
    b_list = calcDiv(b)
    d_list = set(a_list) & set(b_list)
    cnt = 0
    for d in d_list:
        if isPrime(d):
            cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math

def pf(n):
    ans=[1]
    i=2
    while(n!=1):
        if (n%i==0):
            while(n%i==0):
                n=n/i
            ans.append(i)
        i+=1
    return ans

a,b = map(int,input().split())
pfa=pf(a)
pfb=pf(b)
ans=0
for i in pfa:
    if(i in pfb):
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

def pf(n):
    ans=[1]
    i=2
    while(n!=1):
        if (n%i==0):
            while(n%i==0):
                n=n/i
            ans.append(i)
        i+=1
    return ans

a,b = map(int,input().split())
pfa=pf(a)
ans=0
for i in range (len(pfa)):
    if(b%pfa[i]==0):
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a, b = map(int, input().split())
from fractions import gcd
import math

c = gcd(a, b)
i = 2
primes = []
while c > 1:
  if c % i == 0:
    c //= i
    if not i in primes:
      primes.append(i)
  else:
    i += 1
print(len(primes)+1)

Submission status: Time Limit Exceeded

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

inp = [int(e) for e in input().split()]
a = inp[0]
b = inp[1]

count = 0

factors = []
res = [1]

for i in range(1,min(a,b)+1):
  if(a%i == 0 and b%i == 0):
    factors.append(i)
    

#print(factors)
flag = 0
for i in range(1,len(factors)):
  flag = 0
  for e in res:
    if(gcd(factors[i],e) != 1):
      flag = 1
      break;
  if flag == 0:
    res.append(factors[i])


print(len(res))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import numpy as np


def is_prime(a):
    flg = 1

    for i in range(2, a // 2 + 1):
        if is_prime(i) == 1:
            if a % i == 0:
                flg = -1
                break

    return flg


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

if a > b:
    max_num = a // 2
else:
    max_num = b // 2

ans = 1

for i in range(2, max_num // 2):
    if a % i == 0 and b % i == 0:
        if is_prime(i) == 1:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import numpy as np


def is_prime(a):
    flg = 1

    for i in range(2, a // 2 + 1):
        if is_prime(i) == 1:
            if a % i == 0:
                flg = -1
                break

    return flg


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

if a > b:
    max_num = a // 2
else:
    max_num = b // 2

ans = 1

for i in range(2, max_num // 2):
    if is_prime(i) == 1:
        if a % i == 0 and b % i == 0:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

a, b = [int(x) for x in input().split()]

d = 1
d_list = []
while(d <= a and d <= b):
  if a % d == 0 and b % d == 0:
    d_list.append(d)
  d += 1

length = len(d_list)

x = prime_factorize(d_list[-1])
print(len(set(x))+1)

Submission status: Time Limit Exceeded

Solution code:
import math 

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

factors = []
for i in range(1, math.floor(min(a,b))+1):
	if a%i==0 and b%i==0: factors.append(i)


factors = factors[1:]
# print(factors)
for index1, elem1 in enumerate(factors):
	if elem1:
		for index2, elem2 in enumerate(factors):
			if elem1!=elem2:
				if elem2%elem1==0:
					factors[index2] = False

# print(factors)
count = 0
for i in factors:
	if i:
		count += 1
print(count+1)

Submission status: Time Limit Exceeded

Solution code:
a,b=map(int,input().split())
ans=0

def cf(x1,x2):
    cf=[]
    for i in range(1,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

for i in cf(a,b):
    for j in range(2,i):
        if i%j == 0:
            break
    else:
        ans+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
a,b=map(int,input().split())
c=[]
ans=0

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

list_a=make_divisors(a)
list_b=make_divisors(b)

for i in list_a:
    if i in list_b:
        c.append(i)

for i in c:
    for j in range(2,i):
        if i%j == 0:
            break
    else:
        ans+=1

print(ans)