letusgo @ 2023-07-10 17:50:39
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k;
double sum1 = 0,sum2 = 0;
cin >> n >> k;
for(int i = 1; i <= n; i++){
if(i % k == 0){
sum1 += i;
}else if(i % k != 0){
sum2 += i;
}
}
printf("%.1lf %.1lf",sum1/n,sum2/n);
return 0;
}
by letusgo @ 2023-07-10 17:54:50
看出来了,求平均求错了
by intawl @ 2023-07-10 17:55:13
@letusgo 但是平均数不是除以
by _Haoomff_ @ 2023-07-10 17:57:04
@letusgo 不是除以n,是分别除以A类数的个数和B类数的个数
by hujingsong0820 @ 2023-07-24 21:01:39
by Smz1026 @ 2023-08-02 16:20:33
这个求平均数是要设置两个不同的变量来进行整除
by witherbogged @ 2023-11-01 21:00:48
应该专门建a和b两个变量
是k的倍数a++,不是k的倍数b++
printf ("%.1lf %.1lf",sum1 1.0/a,sum2 1.0/b);
a和b都要初始化为0