#P98. 分組平均值
分組平均值
題目描述
給定兩個整數n和k,將所有從1到n的整數分為兩類,第一類包含可以被k整除的整數(換句話說,這些整數是k的倍數);
另一類包含其他整數。
您的任務是計算出每個類的平均值並以一行的方式輸出,數值之間以「 , 」作分隔,各數值精確至小數點後一位。
輸入格式
Two integers n and k
2 <= k <= 100
2 <= n <= 1000000
輸出格式
a float number with precision one decimal place
Samples
["100 16\r\n","10000 32","20 5"]
["56.0 , 50.1\r\n","5008.0 , 5000.3\r\n","12.5 , 10.0"]
提示
[Straight forward solution] You can simply use "loop and range()"to solve the problem.
[Advanced solution] However, naively using loop to classify and get the sum of the numbers may be too costly as the value of n can be up to 1,000,000. You could try to derive the math relationship behind the problem.
原始資料
- Zero1 題號:
a098 - Hydro 題號:
Z0098 - Locale:
zh_TW - Display:
open