lzw2001 @ 2022-02-26 18:17:38
#include <stdio.h>
#include <stdlib.h>
int main()
{ int a[2000],b[1000],c[1000];
int i,x=0,y=0,m,n;
double sum1=0,sum2=0;;
scanf("%d %d",&m,&n);
for(i=0;i<m;i++)
{
a[i]=i+1;
}
for(i=0;i<m;i++)
{
if(a[i]%n==0)
{
b[i]=a[i];
x++;
sum1=sum1+b[i];
}
if(a[i]%n!=0)
{ c[i]=a[i];
y++;
sum2+=c[i];
}
}
printf("%.1f %.1f",sum1/x,sum2/y);
return 0;
}
by huifeidelaohu @ 2022-02-26 18:27:33
# include <iostream>
# include <cstdio>
# include <iomanip>
using namespace std;
int main(){
int m,k;
double y,n;//能被整除和不能
int ysum=0,nsum=0;
scanf("%d%d",&m,&k);
for (int i=1;i<=m;i++){
if (i%k==0){
y+=i;
ysum++;
}`else{
n+=i;
nsum++;
}
}
cout<<fixed<<setprecision(1)<<y/ysum<<" ";
cout<<fixed<<setprecision(1)<<n/nsum;
return 0;
}`