#51589: Python數學思路,沒有大數限制就是爽


henry0985524680@gmail.com (張弘勳)

學校 : 臺北市立建國高級中學
編號 : 192343
來源 : [39.12.34.245]
最後登入時間 :
2024-10-31 20:28:41

a>b就簡單乘10**N就好了
如果a<b
a/b=x
推導(用x是0.0幾的情況,比較容易懂)-->
0.01<=x<0.1
100>=1/x>10
2>=log(1/x)>1
結論要補1個0在前面
 
實作方法
i=10**n,from 1
if i>(1/x):
return n-1
 
程式碼參考
while True:
    try:
        a,b,index=map(int,input().split())
        cunt=""
        ip=str(a//b)
        shit=len(ip)
        if a<b:
            n=1
            shit=0
            while True:
                if 10**n>=b/a:
                    cunt='0'*(n-1)
                    break
                n+=1
        value=cunt+str(a*10**index//(b))
        print(ip+'.'+value[shit:])
    except EOFError:
        break