給定兩個整數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
100 16
56.0 , 50.1
10000 32
5008.0 , 5000.3
20 5
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.
ID | User | Problem | Subject | Hit | Post Date |
沒有發現任何「解題報告」 |