Problem:


Problem J: No Story

Since I got tired to write long problem statements, I decided to make this problem statement short. For given positive integer L, how many pairs of positive integers a, b (a ≤ b) such that LCM(a, b) = L are there? Here, LCM(a, b) stands for the least common multiple of a and b.

Input

For each dataset, an integer L is given in a line. Input terminates when L = 0.

Output

For each dataset, output the number of pairs of a and b.

Constraints

1 ≤ L ≤ 1012

Sample Input

12
9
2
0

Output for the Sample Input

8
3
2



Sample input:
12
9
2
0


Sample output:
8
3
2

Submission status: Wrong Answer

Solution code:
P=[2,3]
Q=[x for x in range(5,1000000) if (x%2!=0 and x%3!=0) ]

while(1):
    p=Q.pop(0)
    P.append(p)
    if p>1e3:
        break
    Q=[x for x in Q if x%p!=0]
P=P+Q

while(1):
    L=int(raw_input())
    if L==0:
        break
    D=[]
    for p in P:
        if p>L:
            break
        if L%p==0:
            d=0
            while(L%p==0):
                d+=1
                L/=p
            D.append(d)
    if len(D)==0:
        print 2
    else:
        k=D[0]+1
        for d in D[1:]:
            k=k*(2*d+1)-d
        print k

Submission status: Wrong Answer

Solution code:
P=[2,3]
Q=[x for x in range(5,1000000) if (x%2!=0 and x%3!=0) ]

while(1):
    p=Q.pop(0)
    P.append(p)
    if p>1e3:
        break
    Q=[x for x in Q if x%p!=0]
P=P+Q

while(1):
    L=int(raw_input())
    if L==0:
        break
    D=[]
    for p in P:
        if p>L:
            break
        if L%p==0:
            d=0
            while(L%p==0):
                d+=1
                L/=p
            D.append(d)
    if len(D)==0:
        if L==1:
            print 1
        else:
            print 2
    else:
        k=D[0]+1
        for d in D[1:]:
            k=k*(2*d+1)-d
        print k

Submission status: Time Limit Exceeded

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

while 1:
	L=input()
	if L==0:break
	s=1
	for i in range(1,L):
		for j in range(i,L+1):
			if i*j/gcd(i,j)==L:
				s+=1
	print s

Submission status: Accepted

Solution code:
# AOJ 1060: No Story
# Python3 2018.6.8 bal4u

MAX = 1000004
ptbl = [ 3,   5,   7,  11,  13,  17,  19,  23,  29,
   31,  37,  41,  43,  47,  53,  59,  61,  67,  71,
   73,  79,  83,  89,  97, 101, 103, 107, 109, 113,
  127, 131, 137, 139, 149, 151, 157, 163, 167, 173,
  179, 181, 191, 193, 197, 199, 211, 223, 227, 229,
  233, 239, 241, 251, 257, 263, 269, 271, 277, 281,
  283, 293, 307, 311, 313, 317, 331, 337, 347, 349,
  353, 359, 367, 373, 379, 383, 389, 397, 401, 409,
  419, 421, 431, 433, 439, 443, 449, 457, 461, 463,
  467, 479, 487, 491, 499, 503, 509, 521, 523, 541,
  547, 557, 563, 569, 571, 577, 587, 593, 599, 601,
  607, 613, 617, 619, 631, 641, 643, 647, 653, 659,
  661, 673, 677, 683, 691, 701, 709, 719, 727, 733,
  739, 743, 751, 757, 761, 769, 773, 787, 797, 809,
  811, 821, 823, 827, 829, 839, 853, 857, 859, 863,
  877, 881, 883, 887, 907, 911, 919, 929, 937, 941,
  947, 953, 967, 971, 977, 983, 991, 997 ]
 
def sieve():
	for p in ptbl:
		for i in range(p*p, MAX, p): tbl[i] = 1
	for i in range(997, MAX, 2):
		if tbl[i] == 0: ptbl.append(i)
 
def prime_factor(n):
	power = []
	if (n & 1) == 0:
		c = 0
		while True:
			n >>= 1
			c += 1
			if n & 1: break
		power.append(c)
	if n <= 1: return power
	if n <= MAX and tbl[n] == 0:
		power.append(1)
		return power
	k = int(n**0.5)
	for p in ptbl:
		if n <= 1: break
		if p > k or (n <= MAX and tbl[n] == 0):
			power.append(1)
			break
		if n % p: continue
		c = 0
		while True:
			n //= p
			c += 1
			if n % p: break
		power.append(c)
	return power

tbl = [0]*MAX
sieve()
while True:
	n = int(input())
	if n == 0: break
	if n == 1:
		print(1)
		continue
	if n <= MAX and (n & 1) and tbl[n] == 0:
		print(2)
		continue
	power = prime_factor(n)
	ans = 1
	for p in power: ans = ans*(1+(p<<1))
	print((ans+1)>>1)

Submission status: Accepted

Solution code:
while True:
    L = input()
    if L == 0:
        break
    n = 2
    ans = 1
    while n * n <= L:
        if L % n == 0:
            S = 0
            while L % n == 0:
                L /= n
                S += 1
            ans *= S * 2 + 1
        n += 1

    if L != 1:
        ans *= 3

    print ans / 2 + 1

Submission status: Accepted

Solution code:
from collections import defaultdict
def soinnsuubunnkai(n):
  dic = defaultdict(int)
  i = 2
  while i * i <= n:
    while n % i == 0:
      dic[i] += 1
      n //= i
    i += 1
  if n != 1:
    dic[n] += 1
  return list(dic.values())
  
def saiki(values, score, ind, end):
  if ind == end:
    return score
  return saiki(values, score * values[ind], ind + 1, end) * 2+ \
         saiki(values, score, ind + 1, end)

while True:
  n = int(input())
  if n == 0:
    break
  values = soinnsuubunnkai(n)
  print((saiki(values, 1, 0, len(values)) + 1) // 2)