A - Chinese Girls' Amusement

Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)

Problem Description

      You must have heard that the Chinese culture is quite different from that of Europe or Russia. So some Chinese habits seem quite unusual or even weird to us.
      So it is known that there is one popular game of Chinese girls. N girls stand forming a circle and throw a ball to each other. First girl holding a ball throws it to the K-th girl on her left (1 ≤ K ≤ N/2). That girl catches the ball and in turn throws it to the K-th girl on her left, and so on. So the ball is passed from one girl to another until it comes back to the first girl. If for example N = 7 and K = 3, the girls receive the ball in the following order: 1, 4, 7, 3, 6, 2, 5, 1.
 To make the game even more interesting the girls want to choose K as large as possible, but they want one condition to hold: each girl must own the ball during the game.

Input

Input contains one integer number N (3 ≤ N ≤ 102000) — the number of Chinese girls taking part in the game.

Output

Output the only number — K that they should choose.

Sample Input

  1. 7
  2. 6

Sample Output

  1. 3
  2. 1

Hint

Java is not prepared !
 
  1. /*
  2. * this code is made by 987690183
  3. * Problem: 1210
  4. * Verdict: Accepted
  5. * Submission Date: 2014-10-14 13:59:15
  6. * Time: 0MS
  7. * Memory: 1680KB
  8. */
  9. #include<iostream>
  10. #include<cstring>
  11. #include<iomanip>
  12. #include<algorithm>
  13. #include<cstdlib>
  14. #include<cstdio>
  15. using namespace std;
  16.  
  17. #define MAXN 9999
  18. #define MAXSIZE 1000
  19. #define DLEN 4
  20.  
  21. class BigNum
  22. {
  23. private:
  24. int a[MAXSIZE]; //可以控制大数的位数
  25. int len; //大数长度
  26. public:
  27. BigNum(){ len = ;memset(a,,sizeof(a)); } //构造函数
  28. BigNum(const int); //将一个int类型的变量转化为大数
  29. BigNum(const char*); //将一个字符串类型的变量转化为大数
  30. BigNum(const BigNum &); //拷贝构造函数
  31. BigNum &operator=(const BigNum &); //重载赋值运算符,大数之间进行赋值运算
  32.  
  33. friend istream& operator>>(istream&, BigNum&); //重载输入运算符
  34. friend ostream& operator<<(ostream&, BigNum&); //重载输出运算符
  35.  
  36. BigNum operator+(const BigNum &) const; //重载加法运算符,两个大数之间的相加运算
  37. BigNum operator-(const BigNum &) const; //重载减法运算符,两个大数之间的相减运算
  38. BigNum operator*(const BigNum &) const; //重载乘法运算符,两个大数之间的相乘运算
  39. BigNum operator/(const int &) const; //重载除法运算符,大数对一个整数进行相除运算
  40.  
  41. BigNum operator^(const int &) const; //大数的n次方运算
  42. int operator%(const int &) const; //大数对一个int类型的变量进行取模运算
  43. bool operator>(const BigNum & T)const; //大数和另一个大数的大小比较
  44. bool operator>(const int & t)const; //大数和一个int类型的变量的大小比较
  45.  
  46. void print(); //输出大数
  47. };
  48. BigNum::BigNum(const int b) //将一个int类型的变量转化为大数
  49. {
  50. int c,d = b;
  51. len = ;
  52. memset(a,,sizeof(a));
  53. while(d > MAXN)
  54. {
  55. c = d - (d / (MAXN + )) * (MAXN + );
  56. d = d / (MAXN + );
  57. a[len++] = c;
  58. }
  59. a[len++] = d;
  60. }
  61. BigNum::BigNum(const char*s) //将一个字符串类型的变量转化为大数
  62. {
  63. int t,k,index,l,i;
  64. memset(a,,sizeof(a));
  65. l=strlen(s);
  66. len=l/DLEN;
  67. if(l%DLEN)
  68. len++;
  69. index=;
  70. for(i=l-;i>=;i-=DLEN)
  71. {
  72. t=;
  73. k=i-DLEN+;
  74. if(k<)
  75. k=;
  76. for(int j=k;j<=i;j++)
  77. t=t*+s[j]-'';
  78. a[index++]=t;
  79. }
  80. }
  81. BigNum::BigNum(const BigNum & T) : len(T.len) //拷贝构造函数
  82. {
  83. int i;
  84. memset(a,,sizeof(a));
  85. for(i = ; i < len ; i++)
  86. a[i] = T.a[i];
  87. }
  88. BigNum & BigNum::operator=(const BigNum & n) //重载赋值运算符,大数之间进行赋值运算
  89. {
  90. int i;
  91. len = n.len;
  92. memset(a,,sizeof(a));
  93. for(i = ; i < len ; i++)
  94. a[i] = n.a[i];
  95. return *this;
  96. }
  97. istream& operator>>(istream & in, BigNum & b) //重载输入运算符
  98. {
  99. char ch[MAXSIZE*];
  100. int i = -;
  101. in>>ch;
  102. int l=strlen(ch);
  103. int count=,sum=;
  104. for(i=l-;i>=;)
  105. {
  106. sum = ;
  107. int t=;
  108. for(int j=;j<&&i>=;j++,i--,t*=)
  109. {
  110. sum+=(ch[i]-'')*t;
  111. }
  112. b.a[count]=sum;
  113. count++;
  114. }
  115. b.len =count++;
  116. return in;
  117.  
  118. }
  119. /*ostream& operator<<(ostream& out, BigNum& b) //重载输出运算符
  120. {
  121. int i;
  122. cout << b.a[b.len - 1];
  123. for(i = b.len - 2 ; i >= 0 ; i--)
  124. {
  125. cout.width(DLEN);
  126. cout.fill('0');
  127. cout << b.a[i];
  128. }
  129. return out;
  130. }*/
  131.  
  132. BigNum BigNum::operator+(const BigNum & T) const //两个大数之间的相加运算
  133. {
  134. BigNum t(*this);
  135. int i,big; //位数
  136. big = T.len > len ? T.len : len;
  137. for(i = ; i < big ; i++)
  138. {
  139. t.a[i] +=T.a[i];
  140. if(t.a[i] > MAXN)
  141. {
  142. t.a[i + ]++;
  143. t.a[i] -=MAXN+;
  144. }
  145. }
  146. if(t.a[big] != )
  147. t.len = big + ;
  148. else
  149. t.len = big;
  150. return t;
  151. }
  152. BigNum BigNum::operator-(const BigNum & T) const //两个大数之间的相减运算
  153. {
  154. int i,j,big;
  155. bool flag;
  156. BigNum t1,t2;
  157. if(*this>T)
  158. {
  159. t1=*this;
  160. t2=T;
  161. flag=;
  162. }
  163. else
  164. {
  165. t1=T;
  166. t2=*this;
  167. flag=;
  168. }
  169. big=t1.len;
  170. for(i = ; i < big ; i++)
  171. {
  172. if(t1.a[i] < t2.a[i])
  173. {
  174. j = i + ;
  175. while(t1.a[j] == )
  176. j++;
  177. t1.a[j--]--;
  178. while(j > i)
  179. t1.a[j--] += MAXN;
  180. t1.a[i] += MAXN + - t2.a[i];
  181. }
  182. else
  183. t1.a[i] -= t2.a[i];
  184. }
  185. t1.len = big;
  186. while(t1.a[len - ] == && t1.len > )
  187. {
  188. t1.len--;
  189. big--;
  190. }
  191. if(flag)
  192. t1.a[big-]=-t1.a[big-];
  193. return t1;
  194. }
  195.  
  196. BigNum BigNum::operator*(const BigNum & T) const //两个大数之间的相乘运算
  197. {
  198. BigNum ret;
  199. int i,j,up;
  200. int temp,temp1;
  201. for(i = ; i < len ; i++)
  202. {
  203. up = ;
  204. for(j = ; j < T.len ; j++)
  205. {
  206. temp = a[i] * T.a[j] + ret.a[i + j] + up;
  207. if(temp > MAXN)
  208. {
  209. temp1 = temp - temp / (MAXN + ) * (MAXN + );
  210. up = temp / (MAXN + );
  211. ret.a[i + j] = temp1;
  212. }
  213. else
  214. {
  215. up = ;
  216. ret.a[i + j] = temp;
  217. }
  218. }
  219. if(up != )
  220. ret.a[i + j] = up;
  221. }
  222. ret.len = i + j;
  223. while(ret.a[ret.len - ] == && ret.len > )
  224. ret.len--;
  225. return ret;
  226. }
  227. BigNum BigNum::operator/(const int & b) const //大数对一个整数进行相除运算
  228. {
  229. BigNum ret;
  230. int i,down = ;
  231. for(i = len - ; i >= ; i--)
  232. {
  233. ret.a[i] = (a[i] + down * (MAXN + )) / b;
  234. down = a[i] + down * (MAXN + ) - ret.a[i] * b;
  235. }
  236. ret.len = len;
  237. while(ret.a[ret.len - ] == && ret.len > )
  238. ret.len--;
  239. return ret;
  240. }
  241. int BigNum::operator %(const int & b) const //大数对一个int类型的变量进行取模运算
  242. {
  243. int i,d=;
  244. for (i = len-; i>=; i--)
  245. {
  246. d = ((d * (MAXN+))% b + a[i])% b;
  247. }
  248. return d;
  249. }
  250. BigNum BigNum::operator^(const int & n) const //大数的n次方运算
  251. {
  252. BigNum t,ret();
  253. int i;
  254. if(n<)
  255. exit(-);
  256. if(n==)
  257. return ;
  258. if(n==)
  259. return *this;
  260. int m=n;
  261. while(m>)
  262. {
  263. t=*this;
  264. for( i=;i<<<=m;i<<=)
  265. {
  266. t=t*t;
  267. }
  268. m-=i;
  269. ret=ret*t;
  270. if(m==)
  271. ret=ret*(*this);
  272. }
  273. return ret;
  274. }
  275. bool BigNum::operator>(const BigNum & T) const //大数和另一个大数的大小比较
  276. {
  277. int ln;
  278. if(len > T.len)
  279. return true;
  280. else if(len == T.len)
  281. {
  282. ln = len - ;
  283. while(a[ln] == T.a[ln] && ln >= )
  284. ln--;
  285. if(ln >= && a[ln] > T.a[ln])
  286. return true;
  287. else
  288. return false;
  289. }
  290. else
  291. return false;
  292. }
  293. bool BigNum::operator >(const int & t) const //大数和一个int类型的变量的大小比较
  294. {
  295. BigNum b(t);
  296. return *this>b;
  297. }
  298.  
  299. void BigNum::print() //输出大数
  300. {
  301. int i;
  302. //cout << a[len - 1];
  303. printf("%d",a[len-]);
  304. for(i = len - ; i >= ; i--)
  305. {
  306. /*cout.width(DLEN);
  307. cout.fill('0');
  308. cout << a[i];*/
  309. printf("%04d",a[i]);
  310. }
  311. //cout << endl;
  312. printf("\n");
  313. }
  314. int main()
  315. {
  316. char zero[]={""};
  317. char one[]={""};
  318. char two[]={""};
  319. char hxl[];
  320. BigNum z,ZERO(zero),ONE(one),TWO(two);
  321. while(gets(hxl)>)
  322. {
  323. BigNum x(hxl);
  324. z=x%;
  325. if(z>)/**奇数**/
  326. {
  327. z=(x-ONE)/;
  328. }
  329. else /**偶数**/
  330. {
  331. x=x/;
  332. z=x%;
  333. if(z>)/**奇数**/
  334. {
  335. z=x-TWO;
  336. }
  337. else /**偶数**/
  338. {
  339. z=x-ONE;
  340. }
  341. }
  342. z.print();
  343. }
  344. return ;
  345. }

Acdream Chinese Girls' Amusement的更多相关文章

  1. ACdream 1210 Chinese Girls' Amusement(高精度)

     Chinese Girls' Amusement Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & ...

  2. ACDream:1210:Chinese Girls' Amusement【水题】

    Chinese Girls' Amusement Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Oth ...

  3. 数学+高精度 ZOJ 2313 Chinese Girls' Amusement

    题目传送门 /* 杭电一题(ACM_steps 2.2.4)的升级版,使用到高精度: 这次不是简单的猜出来的了,求的是GCD (n, k) == 1 最大的k(1, n/2): 1. 若n是奇数,则k ...

  4. 2016NEFU集训第n+5场 A - Chinese Girls' Amusement

    Description       You must have heard that the Chinese culture is quite different from that of Europ ...

  5. A - Chinese Girls' Amusement ZOJ - 2313(大数)

    You must have heard that the Chinese culture is quite different from that of Europe or Russia. So so ...

  6. acdream 1210 Chinese Girls' Amusement (打表找规律)

    题意:有n个女孩围成一个圈从第1号女孩开始有一个球,可以往编号大的抛去(像传绣球一样绕着环来传),每次必须抛给左边第k个人,比如1号会抛给1+k号女孩.给出女孩的人数,如果他们都每个人都想要碰到球一次 ...

  7. SGU 193.Chinese Girls' Amusement

    /* 实际上就是求一个k,满足k<=n/2,且gcd(n,k)=1 如果n为奇数,k为[n/2] 如果n为偶数,k=n/2-1-(n/2)%2 */ #include <iostream& ...

  8. zoj 2313 Chinese Girls' Amusement 解题报告

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1313 题目意思:有 N 个人(编号依次为1~N)围成一个圆圈,要求求 ...

  9. ASC #1

    开始套题训练,第一套ASC题目,记住不放过每一题,多独立思考. Problem A ZOJ 2313 Chinese Girls' Amusement 循环节 题意:给定n,为圆环长度,求k < ...

随机推荐

  1. Python之urllib2

    urllib2 - extensible library for opening URLs Note The urllib2 module has been split across several ...

  2. C++Builder加载Png图片

    有两种方法,一是把该对象的Transparent 的属性设为true,图片的白色代表即为父界面的颜色 而是在头文件加上#include <pngimage.hpp> Image1-> ...

  3. [原创]安装Oracle 11gR2,以及如何在win8下使用plsql develper连接Oracle数据库 ,在这里和大家分享下

    一,关于win8下安装Oracle 11gR2 1.我下载的是Oracle_11gR2_win64.其中有两个包: 注意:在解压了之后将:win64_11gR2_database_2of2\datab ...

  4. [转] linux中常用的命令

    系统信息 arch 显示机器的处理器架构(1) uname -m 显示机器的处理器架构(2) uname -r 显示正在使用的内核版本 dmidecode -q 显示硬件系统部件 - (SMBIOS ...

  5. cordova3.X 运用grunt生成plugin自定义插件骨架

    Cordova提供了一组设备相关的API,通过这组API,移动应用能够以JavaScript访问原生的设备功能,如摄像头.麦克风等.Cordova还提供了一组统一的JavaScript类库,以及为这些 ...

  6. 分享Centos作为WEB服务器的防火墙规则

    # Firewall configuration written by system-config-firewall # Manual customization of this file is no ...

  7. 16---Net基础加强

    更新中,敬请期待............ Xml介绍 xml读写练习 xml练习1 xml练习2

  8. Mysql触发器总结

    触发器(trigger):监视某种情况,并触发某种操作. 触发器创建语法四要素:1.监视地点(table) 2.监视事件(insert/update/delete) 3.触发时间(after/befo ...

  9. 关于centos更新后virtualbox无法使用的问题

    http://blog.csdn.net/zgglj/article/details/50325675

  10. 下拉框分组显示optgroup

    <select> <optgroup label="语言"> <option>中文</option> <option>英 ...