应用同余定理,可以比较简单地求出。其实是个老题目,说法略不同而已——
代码文本:
#include "stdio.h"
int main(int argc,char *argv[]){
int n,m,ans,i;
printf("Please enter n & m(int n,m>0)...\n");
if(scanf("%d%d",&n,&m)==2 && n>0 && m>0){
ans=0;
for(i=1;i<=n;i++)
ans=(ans+m)%i;
printf("\nThe result is %d\n",ans%n+1);
}
else
printf("Input error, exit...\n");
return 0;
}