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 = map(int, input().split())

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

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

def coprime(a, b):
    return gcd(a, b) == 1

l = cf(A, B)
if len(l) == 0:
    print(1)
else:
    c = 1
    for i in range(len(l)):
        for j in range(i):
            if not coprime(l[i], l[j]):
                break
        else:
            c += 1
    print(c)

Submission status: Time Limit Exceeded

Solution code:
a, b = map(int, input().split())
common = []
for i in range(1, min(a, b) + 1):
    if a % i == 0 and b % i == 0:
        common.append(i)

count = 1
for i in range(1, len(common)):
    for j in range(1, i):
        if common[i] % common[j] == 0:
            break
    else:
        count += 1
print(count)

Submission status: Time Limit Exceeded

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

if a > b:
    c = b
    d = a
else:
    c = a
    d = b

i = 2
ans = 1 
incre = True
while True:
    while c % i == 0 and d % i == 0:
        c /= i
        d /= i
        if incre:
            ans += 1
            incre = False
    incre = True
    i += 1
    if i*1 > c:
        break

if d%c == 0 and c > 1:
    ans += 1
    

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
a, b = map(int, input().split())
abMax = fractions.gcd(a, b)
gcdList = [1]
if fractions.gcd(a, b) % 2 == 0:
    gcdList.append(2)
for i in range(1, int((abMax+1)/2)):
    c = 2*i + 1
    if a % c == 0 and b % c == 0:
        swi = 0
        for k in gcdList:
            if fractions.gcd(k, c) != 1:
                swi = 1
                break
        if swi == 0:
            gcdList.append(c)

print(len(gcdList))

Submission status: Time Limit Exceeded

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

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

cfList = cf(a, b)
Comb = itertools.combinations
ans = [cfList[0]]
for l in cfList[1:]:
    ans.append(l)
    for i in Comb(ans, 2):
        temp = cf(i[0], i[1])
        if len(temp) != 1 or temp[0] != 1:
            ans.pop()
            break


print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
a,b = (int(i) for i in input().split())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
  
def is_prime(n):
  for p in range(2, n):
    if n % p == 0:
      return False
  return True

cnt = 0

def 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 = divisors(gcd(a,b))
for i in list:
  if is_prime(i):
    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import fractions

A, B = map(int, input().split())
list = []
if A >= B:
    for a in range(A + 1):
        if a == 0 or a > B: continue
        if A % a == 0 and B % a == 0:
            list.append(a)
else:
    for b in range(B + 1):
        if b == 0: continue
        if A % b == 0 and B % b == 0:
            list.append(b)

stack = []
for element in list:
    break_flg = False
    for stack_element in stack:
        gcd = fractions.gcd(element, stack_element)
        if gcd != 1:
            break_flg = True
            break
    if break_flg == False:
        stack.append(element)
    break_flg = True

print(len(stack))

Submission status: Time Limit Exceeded

Solution code:
import fractions

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


def sieve_of_eratosthenes(N):
    prime_list = [True for _ in range(N + 1)]
    prime_list[0] = False
    prime_list[1] = False
    for p in range(2, int(N ** 0.5) + 1):
        if prime_list[p]:
            for i in range(2 * p, N + 1, p):
                prime_list[i] = False

    return prime_list


gcd_ = fractions.gcd(a, b)
prime_list = sieve_of_eratosthenes(gcd_)
ans = 1
for i in range(1, gcd_+1):
    if gcd_ % i == 0:
        if prime_list[i]:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions

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

cd = set()
i = 1
while i * i <= gcd:
    if gcd % i == 0:
        cd.add(i)
        cd.add(gcd//i)
    i += 1

ans = set()
for n in sorted(cd):
    if n == 1:
        continue
    for j in ans:
        if n**(j-1) % j == 0:
            break
    else:
        ans.add(n)

print(len(ans)+1)

Submission status: Time Limit Exceeded

Solution code:
n = list(map(int, input().split()))

c = [1]

def calc(x):
    for j in range(2, x):
        if x % j == 0:
            return
    c.append(x)
for i in range(2,min(n[0],n[1])+1):
    if n[0] % i == 0 and n[1] % i == 0:
        calc(i)

print(len(c))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
def main():
    def gcd(a, b):
        while b:
            a, b = b, a % b
        return a
    
    def is_prime(n):
        if n == 1:
            return True
        for i in range(2,int(n**0.5)+1):
            if n % i == 0:
                return False
        return True
    
    a,b=map(int,input().split())
    c=gcd(a,b)
    cnt=0
    for i in range(1,c+1):
        if a%i==0 and b%i==0:
            if is_prime(i):
                cnt+=1
                
            
    print(cnt)
    
    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

def divisor(n):
  i = 1
  table = []
  while i * i <= n:
    if n%i == 0:
      table.append(i)
      table.append(n//i)
    i += 1
  table = list(set(table))
  return table

def sieve(n):
  is_prime = [True for _ in range(n+1)]
  is_prime[0] = False
  for i in range(2, n+1):
    if is_prime[i-1]:
      j = 2 * i
      while j <= n:
        is_prime[j-1] = False
        j += i
  table = [ i for i in range(1, n+1) if is_prime[i-1]]
  return is_prime, table
  
aset = set(divisor(a))
bset = set(divisor(b))
fin = aset & bset
finmax = max(fin)

_, sosu = sieve(finmax)
print(1+len(set(sosu)&fin))

Submission status: Time Limit Exceeded

Solution code:
import fractions
#A=int(input())
#A=list(map(int,(input().split())))
A,B=list(map(int,(input().split())))
C=fractions.gcd(A,B)
lis=[]
waru=2
while (C!=1):
	
	if C%waru==0:
		lis.append(waru)
		while(C%waru==0):
			C/=waru
	waru+=1
print(len(lis)+1)

Submission status: Time Limit Exceeded

Solution code:
# from math import gcd
from fractions import gcd  # gcd: 2つの正の数を渡すと最大公約数を返す  # Atcoder ではこっち
from collections import defaultdict

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

# 正の公約数
cf=[] # 1が公約数なのは当然
for i in range(2,min(a, b)+1):
    if a % i == 0 and b % i == 0:
        cf.append(i)

# print(cf)

# 素数チェック
def is_prime(n):
    """
    Assumes that n is a positive natural number
    https://www.rookieslab.com/posts/fastest-way-to-check-if-a-number-is-prime-or-not
    """
    # We know 1 is not a prime number
    if n == 1:
        return False

    i = 2
    # This will loop from 2 to int(sqrt(x))
    while i*i <= n:
        # Check if i divides x without leaving a remainder
        if n % i == 0:
            # This means that n has a factor in between 2 and sqrt(n)
            # So it is not a prime number
            return False
        i += 1
    # If we did not find any factor in the above loop,
    # then n is a prime number
    return True

# disjoint_dict = defaultdict(lambda: True)

disjoint_dict = {i: True for i in cf}

# for i in range(0, len(cf)-1):

for i, cf_i in enumerate(cf):

    if is_prime(cf_i):  # 素数である
        continue
    if disjoint_dict[cf_i] == False:  # 既に互いに素ではないパターンが発見されている
        continue

    # for j in range(i, len(cf)):
    for cf_j in cf[i:]:
        if disjoint_dict[cf_j] == False:
            continue

        if gcd(cf_i, cf_j) != 1:
            disjoint_dict[cf_j] = False

# print(disjoint_dict)
print(sum(disjoint_dict.values())+1)  # 1は必ず全ての数字に対して互いに素なので +1 する

Submission status: Time Limit Exceeded

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

def gcd(m, n) :
    while n :
        m, n = n, m % n
    return m

ret = 0
x = gcd(A, B)
if x % 2 == 0 :
    ret += 1
    while x % 2 == 0 :
        x //= 2
        
i = 3
while x != 1 :
    if x % i == 0 :
        ret += 1
        x //= i
        
    while x % i == 0 :
        x //= i
        
    i += 2
        
print(ret + 1)

Submission status: Time Limit Exceeded

Solution code:
import math
import random


# 素因数分解
class Prime:
    seed_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

    def is_prime(self, n):
        is_prime_common = self.is_prime_common(n)
        if is_prime_common is not None:
            return is_prime_common

        if n < 2000000:
            return self.is_prime_brute_force(n)
        else:
            return self.is_prime_miller_rabin(n)

    def is_prime_common(self, n):
        if n == 1: return False
        if n in Prime.seed_primes: return True
        if any(map(lambda x: n % x == 0, self.seed_primes)): return False

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

    def is_prime_miller_rabin(self, n):
        d = n - 1
        while d & 1 == 0:
            d >>= 1

        # use one of these lines / upper is more efficient.
        witnesses = self.get_witnesses(n)
        # witnesses = [random.randint(1, n - 1) for _ in range(100)]

        for w in witnesses:
            y = pow(w, d, n)

            while d != n - 1 and y != 1 and y != n - 1:
                y = (y * y) % n
                d <<= 1

            if y != n - 1 and d & 1 == 0:
                return False

        return True

    def get_witnesses(self, num):
        def _get_range(num):
            if num < 2047:
                return 1
            if num < 1373653:
                return 2
            if num < 25326001:
                return 3
            if num < 3215031751:
                return 4
            if num < 2152302898747:
                return 5
            if num < 3474749660383:
                return 6
            if num < 341550071728321:
                return 7
            if num < 3825123056546413051:
                return 9
            return 12

        return self.seed_primes[:_get_range(num)]

    def gcd(self, a, b):
        if a < b:
            return self.gcd(b, a)
        if b == 0:
            return a
        while b:
            a, b = b, a % b
        return a

    @staticmethod
    def f(x, n, seed):
        p = Prime.seed_primes[seed % len(Prime.seed_primes)]
        return (p * x + seed) % n

    def find_factor(self, n, seed=1):
        if self.is_prime(n):
            return n

        x, y, d = 2, 2, 1
        count = 0
        while d == 1:
            count += 1
            x = self.f(x, n, seed)
            y = self.f(self.f(y, n, seed), n, seed)
            d = self.gcd(abs(x - y), n)

        if d == n:
            return self.find_factor(n, seed+1)
        return self.find_factor(d)

    def find_factors(self, n):
        primes = {}
        if self.is_prime(n):
            primes[n] = 1
            return primes

        while n > 1:
            factor = self.find_factor(n)

            primes.setdefault(factor, 0)
            primes[factor] += 1

            n //= factor

        return primes

a, b = list(map(int, input().split()))
p = Prime()
fa = sorted(list(p.find_factors(a).keys()))
fb = sorted(list(p.find_factors(b).keys()))
c = 1
try:
    pa = fa.pop(0)
    pb = fb.pop(0)
    while True:
        if pa == pb:
            c += 1
            pa = fa.pop(0)
            pb = fb.pop(0)
        elif pa > pb:
            pb = fb.pop(0)
        else:
            pa = fa.pop(0)
except:
    pass
print(c)

Submission status: Time Limit Exceeded

Solution code:
A,B = map(int, input().split())
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
result = []
def delist(C):
    result.append(C[0])
    if len(C) == 1:
        return result
    else:
        CC = []
        for c in C:
            if c%C[0] != 0:
                CC.append(c)
        return delist(CC)
cflist = cf(A, B)
if len(cflist) == 0:
    print(1)
else:
    print(len(delist(cflist)) + 1)

Submission status: Time Limit Exceeded

Solution code:
def div(n, m):
  if n > m:
    n = m
  d = []
  for i in range(1, n+1):
    if n % i == 0 and m % i == 0:
      d.append(i)
  return d

a, b = map(int, input().split())
lc = div(a,b)
la = []
for i in lc:
  if la:
    for j in la:
      if j != 1 and i % j == 0:
        break
    else:
      la.append(i)
  else:
    la.append(i)
print(len(la))

Submission status: Time Limit Exceeded

Solution code:
import math
a,b=map(int,input().split())
a,b=min(a,b),max(a,b)
ans=1
for i in range(2,a+1):
  if a%i==0:
    if b%i==0:
      ans+=1
    while a%i==0:
      a//=i
    if a==1:
      break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a, b = (int(i) for i in input().split())
kouyaku = [1]
ans = 0
for i in range(1,min(a,b)+1):
    if (a % i == 0) and (b % i == 0):
        if i == 1:
            ans += 1
        else:
            for j in kouyaku:
                if j == 1:
                    pass
                elif (i%j == 0):
                    break
            else:
                kouyaku.append(i)
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

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

res = len([i for i in lst if is_prime(i)])

print(res)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    a, b = map(int, input().split())
    d = []
    for i in range(2, min(a, b) + 1):
        if any([i % di == 0 for di in d]):
            continue
        elif a % i == 0 and b % i == 0:
            d.append(i)
    d.append(1)
    print(len(d))


if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
import fractions

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

# 公約数の中の素数の数を考えれば良いのではないか？

n = fractions.gcd(A, B)

data = [i + 1 for i in range(1, n)]
ans = []

while data != []:
  p = data[0]
  if A % p == 0 and B % p == 0:
    ans.append(p)
  data = [e for e in data if e % p != 0]

ans.insert(0, 1)

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import math

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

cf = []

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

# print(cf)
ans = 0
so = True
for k in cf:
#  dest = int(math.sqrt(k))
  for j in range(2, k):
    if k % j == 0:
      so = False
  if so:
    ans += 1
  so = True
  

print(ans+1)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    a, b = map(int, input().split())
    d = []
    for i in range(2, min(a, b) + 1):
        if any([i % di == 0 for di in d]):
            continue
        if a % i == 0 and b % i == 0 and all([i % di != 0 for di in d]):
            d.append(i)
    d.append(1)
    print(len(d))


if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
import math
A,B = map(int, input().split())
num_set = set()
i=2
while True:
    if(A%i==0 and B%i==0):
        num_set.add(i)
        A = A//i
        B = B//i
    elif(A==i or B==i):
        break
    else:
        i = i+1
print(len(num_set)+1)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
def f(n):
    arr = deque()
    tmp = n
    for i in range(2,n//1 + 1):
        if tmp % i == 0:
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            arr.append(i)
    if tmp != 1:
        arr.append(tmp)
    if arr == []:
        arr.append(n)
    return arr

A, B = map(int, input().split())
arrA = f(A)
arrB = f(B)
if len(arrA )> len(arrB):
    arrA, arrB = arrB, arrA

cnt = 1
for i in range(len(arrA)):
    if arrA[i] in arrB:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math

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

def common_divisor(n):
  if n == 1:
    return [1]
  ret = []
  for i in range(1,math.ceil(math.sqrt(n))):
    if n%i==0:
      ret.append(i)
      ret.append(n//i)      
  return sorted(ret)

ca = common_divisor(a)
cb = common_divisor(b)

sa = set(ca)
c = sa.intersection(cb)

primes = lambda n:[i for i in range(1,n+1) if len([j for j in range(1,i+1) if i%j==0]) ==2]

sp = primes(max(c))
sp.append(1)

print(len(c.intersection(sp)))

Submission status: Time Limit Exceeded

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

A,B = map(int,input().split())
list = cf(A,B)
c = 1
for i in list:
    for j in range(2, i+1):
        if i % j == 0:
            if i == j:
                c +=1
            else:
                break
print(c)

Submission status: Time Limit Exceeded

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


def cf(a, b):
    return [i for i in range(2, (min(a, b)) + 1) if a % i == 0 and b % i == 0]


def furui(data):
    for d in data:
        data = [x for x in data if (x == d or x % d != 0)]
    return data


data = cf(a, b)
ans = furui(data)
print(len(ans) + 1)

Submission status: Time Limit Exceeded

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

res = []
for i in range(2, min(A, B)+1):
    if A % i == 0:
        if B % i == 0:
            res.append(i)

i = 0
while i < len(res)-1:
    j = i + 1
    while j < len(res):
        if res[j] % res[i] == 0:
            res.pop(j)
        else:
            j += 1
        
    i += 1

print(len(res)+1)

Submission status: Time Limit Exceeded

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

def gcd(a, b):
	if b == 0:
		return(a)
	else :
		return gcd(b, a % b)
		
a = gcd(A, B)
ctr = 1
gusu = 0

for i in range(2, a + 1):
	if not (gusu == 1 and i % 2 == 0):
		do = 0
		while a % i == 0:
			a /= i
			do = 1
			if a == 1:
				break
		if do:
			ctr += 1
		if do and i == 2:
			gusu = 1
		if a == 1:
			break
		
print(ctr)

Submission status: Time Limit Exceeded

Solution code:
a,b = (int(i) for i in input().split())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
def divisor(n): #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
  
def is_prime(n):
  for p in range(2, n):
    if n % p == 0:
      return False
  return True

cnt = 0
for i in divisor(gcd(a,b)):
  if is_prime(i):
    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
a, b = map(int, input().split())
 
tmpA = max(a, b)
tmpB = min(a, b)
 
while tmpB != 0:
    newB = tmpA % tmpB
    tmpA = tmpB
    tmpB = newB
 
already = [0 for i in range(tmpA)]
already[0] = 1
pointer = 1
tmp = tmpA
 
while tmp != 1:
    for i in range(2, tmp // already[pointer - 1]):
        if tmp % i == 0:
            already[pointer] = i
            pointer += 1
            tmp = tmp // i
            break
    else:
        already[pointer] = tmp
        break

print(max(len(set(already)) - 1, 1))

Submission status: Time Limit Exceeded

Solution code:
AB = input().split(' ')
A = int(AB[0])
B = int(AB[1])

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)
    cf.insert(0,1)
    return cf

def check_cf(x1,x2):
    for i in range(2,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            return False
    return True
candidate = cf(A,B)
decided_list = [candidate[0]]

for i in range(1,len(candidate)):
    flag = True
    for s in range(i):
        if not check_cf(candidate[i],candidate[s]):
            flag = False
            break
    if flag:
        decided_list.append(candidate[i])
print(len(decided_list))

Submission status: Time Limit Exceeded

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

def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1

def resolve():
    a,b=map(int,input().split())
    g=cf(a,b)
    ans=1
    for h in g:
        if is_prime(h):
            ans+=1
    print(ans)
resolve()

Submission status: Time Limit Exceeded

Solution code:
def gcd(a,b):
	if a==0:
		return(b)
	return(gcd(b%a,a))
a,b=map(int,input().split())
g=gcd(a,b)
divide=2

ans=1
while(g!=1):
	if g%divide==0:
		ans+=1
		while(g%divide==0):
			g//=divide
	divide+=1
print(ans)

Submission status: Time Limit Exceeded

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

A, B = map(int, input().split())
gcd_AB = gcd(A, B)
dA=[x for x in range(1, gcd_AB) if A%x == 0]
dB=[x for x in range(1, gcd_AB) if B%x == 0]
cd=[x for x in dA if x in dB]
cd.append(gcd_AB)
#print(A, B, gcd_AB)
#print(dA)
#print(dB)
#print(cd)
so_list = []
for i in cd[1:]:
  ok=True
  for s in so_list:
    if i % s == 0:
      ok=False
      break
  if ok:
    so_list.append(i)

print(len(so_list) + 1)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    a, b = map(int, input().split())
    d = []
    for i in range(2, min(a, b) + 1):
        if a % i == 0 and b % i == 0 and all([i % di != 0 for di in d]):
            d.append(i)
    d.append(1)
    print(len(d))


if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
import functools
import math

a,b = input().split()


def divisor(n): #nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

a = divisor(int(a))
b = divisor(int(b))
ans_list = list(set(a) & set(b))

# print(ans_list)
an = 0

for i in range(len(ans_list)):
    hantei = []
    hantei = divisor(ans_list[i])
#     print(hantei)
    if len(hantei) == 2 or len(hantei) == 1:
#         print("1")
        an += 1
print(an)

Submission status: Time Limit Exceeded

Solution code:
a, b = map(int, input().split())
common = []
for i in range(1, min(a, b) + 1):
    if a % i == 0 and b % i == 0:
        common.append(i)

count = 1
for i in range(1, len(common)):
    for j in range(2, common[i]):
        if common[i] % j == 0:
            break
    else:
        count += 1
print(count)

Submission status: Time Limit Exceeded

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

a, b = list(map(int, input().split()))
cf = cul(a, b)
n = len(cf)
c = 0
for i in range(0, n):
  d = []
  for j in range(0, i):
    d.extend(cul(cf[i], cf[j]))
  if len(d)==i:
    c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
def c_div(a, b):
    my_list = []
    for i in range(2, min(a, b)+1):
        flag = True
        for item in my_list:
            if i % item == 0:
                flag = False
                break
        if flag and a % i == 0 and b % i == 0:
            my_list.append(i)
    return len(my_list)+1


# スペース区切りの整数の入力
a, b = map(int, input().split())
print(c_div(a, b))

Submission status: Time Limit Exceeded

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


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

max_gcd = gcd(a,b)

primes = []
for i in range(2,max_gcd+1):
  if any(i % prime == 0 for prime in primes):
    continue
  primes += [i]
primes = [1] + primes
  
ans = sum(max_gcd % prime == 0 for prime in primes)

print(ans)

Submission status: Time Limit Exceeded

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

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

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

list = [1]
list.extend(cf(A,B))
cnt = 1
for i in list:
    if is_prime(i) == True:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

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

def coprime(a, b):
    return gcd(a, b) == 1

mini = min(A, B)
cmlist = []
for i in range(1, mini+1):
  if A % i == 0 and B % i == 0:
    can_append = True
    for cm in cmlist:
      if not coprime(cm, i):
        can_append = False
        break
    if can_append:
	    cmlist.append(i)

print(len(cmlist))

Submission status: Time Limit Exceeded

Solution code:
#from collections import defaultdict 
import copy
A,B = map(int, input().split())

num = min(A,B)
tmps = {}
p = 2
while p <= num:
    if A % p == 0 and B % p == 0:
        tmps[p] = True
    p += 1

#print(tmps)
d = copy.deepcopy(tmps)
for k in tmps.keys():
    if d.get(k, False):
        aaa = copy.deepcopy(d)
        for n in d.keys():
            if k == n:
                continue
            if n > k and n % k == 0:
                aaa.pop(n)
        d = aaa

print(len(d.keys())+1)

Submission status: Time Limit Exceeded

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

CommonDivs =[]
for i in range(1, min(A, B)+1): 
    if A%i==B%i==0: 
        CommonDivs.append(i)
        
#print(CommonDivs)

def primes(nums):
    n = len(nums)
    is_prime = [True] * n
    is_prime[0] = True
    is_prime[1] = True
    for i in range(1, n):
        if not is_prime[i]:
            continue
        for j in range(i+1, n):
            if nums[j] % nums[i] == 0:
                is_prime[j] = False
    return {nums[i]: True for i in range(n) if is_prime[i]}

if len(CommonDivs) == 1:
    print(1)
else:
    print(len(primes(CommonDivs)))

Submission status: Time Limit Exceeded

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

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

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

l = []
l.append(k[0])
ans = 1

for i in range(1,len(k)):
	flag = True
	for j in range(len(l)):
		if not gcd(k[i],l[j]):
			flag = False
			break
	if flag:
		l.append(k[i])
		ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def div(n):
  d = set()
  for i in range(1, n+1):
    if n % i == 0:
      d.add(i)
  return d

a, b = map(int, input().split())
lc = list(div(a) & div(b))
lc.sort()
la = []
for i in lc:
  if la:
    for j in la:
      if j != 1 and i % j == 0:
        break
    else:
      la.append(i)
  else:
    la.append(i)
print(len(la))

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

def is_prime(n):
    if n == 1: return False

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

cf = cf(a, b)
counter = 0
for i in cf:
    if is_prime(i) or i == 1:
        counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from itertools import combinations
def cf(x1,x2):
    cf=[1]
    for i in range(2,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf
def compromise(x1, x2):
    f = fractions.gcd(x1, x2)
    return f == 1

a, b = map(int, input().split())
cfs = cf(a, b)
club = []
for i in range(len(cfs)):
    if i == 0:
        club.append(cfs[i])
    else:
        flag = True
        for c in club:
            if not compromise(cfs[i], c):
                flag = False
        if flag:
            club.append(cfs[i])
print(len(club))