2017年12月23日 星期六

a035: 位數

a035: 位數

'''
你知道2^10是幾位數嗎?答案是4位數,
當然你可以一個一個乘開,得到2^10=1024,
而數學家發明了 log 函數,
你可以用它快速地求出 ab 是幾位數。

輸入說明:
輸入兩個正整數 a、b (1<=a、b<=1000000)。
輸出說明:
請輸出 a^b 是幾位數。
範例輸入:help

2 10
範例輸出 :

4
'''
print("輸入兩個正整數 a、b (1<=a、b<=1000000)。")
print("輸入 a、b ,用逗號隔開 > ",end='')
a,b=map(int,input().split(','))

C=a**b
print(a,"^",b,"是",len(str(C)),"位數")
print(a,"的",b,"次方 =",C)


============ RESTART: F:/Python_APSC/a035.py ======================
輸入兩個正整數 a、b (1<=a、b<=1000000)。
輸入 a、b ,用逗號隔開 > 3,10
3 ^ 10 是 5 位數
3 的 10 次方 = 59049
>>> 
============= RESTART: F:/Python_APSC/a035.py ======================
輸入兩個正整數 a、b (1<=a、b<=1000000)。
輸入 a、b ,用逗號隔開 > 2,10
2 ^ 10 是 4 位數
2 的 10 次方 = 1024
>>> 

沒有留言:

張貼留言

2024年4月24日 星期三 Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --2

 2024年4月24日 星期三 Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --2 AngularJS 實例 <!DOCTYPE html> <html> <head> &...