题目描述
Surely you have made the experience that when too many people use the Internet simultaneously, the net becomes very, very slow. 
To put an end to this problem, the University of Ulm has developed a contingency scheme for times of peak load to cut off net access for some cities of the country in a systematic, totally fair manner. Germany's cities were enumerated randomly from 1 to n. Freiburg was number 1, Ulm was number 2, Karlsruhe was number 3, and so on in a purely random order. 
Then a number m would be picked at random, and Internet access would first be cut off in city 1 (clearly the fairest starting point) and then in every mth city after that, wrapping around to 1 after n, and ignoring cities already cut off. For example, if n=17 and m=5, net access would be cut off to the cities in the order [1,6,11,16,5,12,2,9,17,10,4,15,14,3,8,13,7]. The problem is that it is clearly fairest to cut off Ulm last (after all, this is where the best programmers come from), so for a given n, the random number m needs to be carefully chosen so that city 2 is the last city selected.

Your job is to write a program that will read in a number of cities n and then determine the smallest integer m that will ensure that Ulm can surf the net while the rest of the country is cut off.
输入
The input will contain one or more lines, each line containing one integer n with 3 <= n < 150, representing the number of cities in the country. 
Input is terminated by a value of zero (0) for n.
输出
For each line of the input, print one line containing the integer m fulfilling the requirement specified above.
样例输入
大家都有这种经验,当太多的人同时使用互联网的时候,网络会变得非常,非常缓慢。为了结决这一问题,北师大制定了一项应急计划,在网络使用高峰期切断一些连接以保证网络的畅通。所有的网络连接都将被标号(从1开始,依次是2号,3号……)。当应急计划启动的时候,首先切断1号连接,然后切断1号之后的第M个连接,在然后是上一个被切断之后的第M个连接,以此类推。例如,如果有17个连接,并且M=5,则依次切断的顺序为[1,6,11,16,5,12,2,9,17,10,4,15,14,3,8,13,7]。DXY同学大公无私地将自己的机器设置为1连接,而ZSL同学的机器为2号连接。原本这种切断连接的方式是很公平的,不过ZSL同学想要知道当M为多少时,他的机器会被最后一个切断连接(他果然很不厚道)。                
 
Input
输入不止一行,每一行都只有一个无符号整数N,且 3 <= n < 150。当输入0的时候程序退出。                
 
Output
对于每一行的输入,输出一个最小的值M,满足ZSL同学的2号连接会被最后一个切断。                
 
Sample Input
3
4
5
6
7
8
9
10
11
12
0
Sample Output
2
5
2
4
3
11
2
3
8
16

//第一个人总是最先被删除的。因此可以把该问题看成是n-1个人的问题,
//希望最后问题中最原始的2留下来,找这个递增的m  */
#include<stdio.h>
#include<string.h>
#include<math.h>int call(int n,int m)
{int i,s=0;for(i=2;i<=n-1;i++){s=(s+m)%i;
//如果s从1开始,则(s+m-1)%i+1  }return s;
}
int main()
{int n,i;while(scanf("%d",&n),n){if(n==0)break;for(i=1;;i++){if(call(n,i)==0){//编号为1的城市已经出列,所以第二座城市现在编号为1,但递推式的第一个值为0  printf("%d\n",i);break;}}}return 0;
}

C/C++ Eeny Meeny Moo相关推荐

  1. POJ1212 HDU1650 UVA180 LA5240 Eeny Meeny【约瑟夫环】

    Eeny Meeny Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 348 Accepted: 101 Description ...

  2. Competitive Programming 3题解

    题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...

  3. Competitive Programming专题题解(1)

    Competitive Programming题解 AOAPC I: Beginning Algorithm Contests 题解 CP2-1.1.1 Easy(Ad Hoc Problems) P ...

  4. 杭电oj题目题型分类(转)

    1001 整数求和 水题 1002 C语言实验题--两个数比较 水题 1003 1.2.3.4.5... 简单题 1004 渊子赛马 排序+贪心的方法归并 1005 Hero In Maze 广度搜索 ...

  5. HDOJ题目分类大全

    版权声明:本文为博主原创文章,欢迎转载,转载请注明本文链接! https://blog.csdn.net/qq_38238041/article/details/78178043 杭电里面有很多题目, ...

  6. HDU题目分类大全【大集合】

    基础题: 1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029.  1032.1037.1040.1048.1056.105 ...

  7. POJ前面的题目算法思路【转】

    1000 A+B Problem 送分题 49% 2005-5-7 1001 Exponentiation 高精度 85% 2005-5-7 1002 487-3279 n/a 90% 2005-5- ...

  8. 杭电OJ题目分类(转载)

    1001 整数求和 水题 1002 C语言实验题--两个数比较 水题 1003 1.2.3.4.5... 简单题 1004 渊子赛马 排序+贪心的方法归并 1005 Hero In Maze 广度搜索 ...

  9. HOJ题目分类//放这儿没事刷刷学算法!嘻嘻!

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

最新文章

  1. 综合中央计算机系统简称,全国计算机等级考试级试题及答案.doc
  2. 如何获取组SPGroup的描述Description信息
  3. Ubuntu系统初识-常用命令和软件安装
  4. 关于线程的执行顺序,可能真的只是你以为的你以为
  5. 谱比法计算岩石的品质因子的c语言程序,地层品质因子计算方法及系统与流程...
  6. 【微型计算机原理与接口技术】80X86微处理器发展与内部结构
  7. using c++11 standerd in qt
  8. Saltstack远程执行命令(3)
  9. Java程序设计教程(第三版) 雍俊海 9.6 答案/代码
  10. 计算机仿真 是核心吗,《计算机仿真》北大核心
  11. Windows下运行Makefile
  12. 喧喧发布 2.5.1 版本,支持移动版和桌面端同时登录
  13. 黑苹果、win双系统,丢失黑苹果引导,如何修复黑苹果的引导
  14. 盘点历史上曾肆虐一时的电脑病毒,你知道几种?
  15. 微信公众号发布投票教程
  16. 解决Past duration X.XXXX too large警告
  17. 360 android系统 流量,360手机卫士Android版增流量监控
  18. 域名可以转让注册人吗_别人帮注册的域名怎么过户
  19. LeetCode-334. 递增的三元子序列 Python3版本
  20. HBase分享 | Flink+HBase场景化解决方案

热门文章

  1. JavaScript 动态数据处理
  2. 共享内存(shmget,shmat,shmdt,shmctl)
  3. 如何让百度搜到我的网站或博客
  4. stata学习笔记|OLS回归
  5. 电瓶车续航测试软件,谁续航最牛:24款电动汽车实测数据全曝光
  6. 西南大学844信号与系统考研经验(高分上岸学姐)
  7. mysql master_log_file_change master 未指定master_log_file
  8. uni-app项目使用多语言切换功能
  9. ERP采购管理系统软件
  10. [有感]_给天蓝管理层的诺干建议