問題文

#coding:utf-8

import math, fractions

t = []
for i in range(int(math.sqrt(10000)), 1, -1):
	 t.append(i**2)

dic = {}
for r in range(2, 10000 + 1):
	 u = [str(r)]
	 if r in t:
			 dic.update(dict.fromkeys(u, [int(math.sqrt(r)), 1]))
	 else:
		 x = 1
		 for w in t:
			 if r % w == 0:
				 r /= w
				 x *= (int(math.sqrt(w)))
		 if x > 1:
			 dic.update(dict.fromkeys(u, [int(x), r]))
		 else:
			 dic.update(dict.fromkeys(u, [1, r]))

for a in range(1, 101):
	 for b in range(2, 101):  
		 c = a * b   
		 z = dic[str(c)]
		 if z[0] == 1:
			 print "√" + str(a) + "/" + "√" + str(b) + " -> " + "√" + str(z[1]) + "/" + str(b)
		 elif z[1] == 1:
			 print  "√" + str(a) + "/" + "√" + str(b) + " -> " + str(fractions.Fraction(z[0], b))
		 else:
			 if fractions.Fraction(z[0], b) == 1:
				 print  "√" + str(a) + "/" + "√" + str(b) + " -> " + "√" + str(z[1])
			 else:
				 print  "√" + str(a) + "/" + "√" + str(b) + " -> " + "(" + str((fractions.Fraction(z[0], b))) + ")" + "*" + "√" + str(z[1])

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS