还没读懂这道题什么意思?
大家举个例子说说
谢谢!
/*---------------------------------------------------------------------------
File name: Joseph.c
Author: HJin (email: fish_sea_bird [at] yahoo [dot] com )
Created on: 7/31/2007 11:36:07
Environment: Windows XP Professional SP2 English +
Visual Studio 2005 v8.0.50727.762
Modification history:
===========================================================================
Sample output:
3 5
3 1 5 2 4
5 25
5 10 15 20 25 6 12 18 24 7 14 22 4 16 1 11 23 13 3 21 19 2 9 17 8
*/
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
int main()
{
int *a, M, N, i, left, s;
while(scanf("%d%d", &M, &N)!=-1)
{
a = (int*)malloc(N*sizeof(int));
if(a==NULL)
exit(0);
for(i=0; i<N; ++i)
a[i] = 1;
left = N;
i=0;
s=0;
while(left>0)
{
if(i==N)
i=0;
s+=a[i];
if(s==M)
{
s=0;
--left;
a[i]=0;
printf("%d ", i+1);
}
++i;
}
printf("\n\n");
free(a);
}
return 0;
}