Bilipaigen @ 2021-05-02 17:00:32
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k;
double a = 0,b = 0,c = 0,d = 0;
cin>>n>>k;
for (int i = n;i>1;i--)
if (i%k == 0){
a += i;
c++;
}
else if (i%k != 0){
b += i;
d++;
}
printf("%.1lf %.1lf",a/c,b/d);
return 0;
}
by _caiji_ @ 2021-05-02 17:11:17
@Bilipaigen
for (int i = n;i>1;i--)
// ^~~
漏了
by ALWAYS_Lyz_Zqbx @ 2021-05-02 17:11:34
#include<bits/stdc++.h>
using namespace std;
int n,k,cnt1,cnt2;
double sum1,sum2;
int main(){
cin>>n>>k;
for(int i=1;i<=n;i++)
if(i%k==0)
sum1+=i,cnt1++;
else
sum2+=i,cnt2++;
printf("%.1lf %.1lf",sum1/cnt1,sum2/cnt2);
return 0;
}
by Bilipaigen @ 2021-05-03 11:30:29
@caijianhong 谢谢,改回来了