⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1309.txt

📁 北大ACM题目例程 详细的解答过程 程序实现 算法分析
💻 TXT
字号:


#include<stdio.h>
#include<math.h>
main()
{

	long N,i,j,t,ans;
	int flag=0;
	//FILE in,out
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	
	scanf("%ld",&N);
	while(N>0)
	{
		flag=0;
		for(j=N-1;j>1;j--)
		{
			
			i=0;
			t=N;
			while(t%j==1)
			{
				t-=(t/j+1);
				i++;
			}
			if(t%j==0&&i==j)
			{
				flag=1;
				ans=j;
				printf("%ld coconuts, %ld people and 1 monkey\n",N,ans);

				break;
			}
		}
		if(flag==0)
			printf("%ld coconuts, no solution\n",N);
	
		scanf("%ld",&N);
	}

	
	
//	fclose(stdin);
//	fclose(stdout);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -