题目思路:用一个while循环,如果a不等于1,就把a除以2,计数器加1,最后输出计数器即可。
#include<stdio.h>
int main()
{
int n, k,i,b=0,c=0;
double s1=0, s2=0;
scanf("%d %d", &n, &k);
for ( i = 1; i <= n; i++)
{
if (i % k == 0)
{
s1 = s1 + i;
c++;
}
else
{
s2 = s2 + i;
b++;}
}
printf("%.1f %.1f", s1 / c, s2 / b);
return 0;
}