a098: 分組平均值
Tags :
Accepted rate : 118人/123人 ( 96% ) [非即時]
評分方式:
Strictly

最近更新 : 2022-04-27 17:10

Content

給定兩個整數n和k,將所有從1到n的整數分為兩類,第一類包含可以被k整除的整數(換句話說,這些整數是k的倍數);

另一類包含其他整數。

 

您的任務是計算出每個類的平均值並以一行的方式輸出,數值之間以「 , 」作分隔,各數值精確至小數點後一位。

Input

Two integers n and k

2 <= k <= 100

2 <= n <= 1000000

Output

a float number with precision one decimal place

Sample Input #1
100 16
Sample Output #1
56.0 , 50.1
Sample Input #2
10000 32
Sample Output #2
5008.0 , 5000.3
Sample Input #3
20 5
Sample Output #3
12.5 , 10.0
測資資訊:
記憶體限制: 64 MB
不公開 測資點#0 (33%): 1.0s , <1K
不公開 測資點#1 (33%): 1.0s , <1K
不公開 測資點#2 (34%): 1.0s , <1K
Hint :

[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.

Tags:
出處:
[管理者:
kichan@g.pui... (陳嘉賢CHAN KA IN)
]


ID User Problem Subject Hit Post Date
1608
1551773-x@g.... (S1B16梁日誠)
a098
ans
101 2024-05-31 15:27