Chinese Girls' Amusement

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.

This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.

Input
Input file contains one integer number N (3 <= N <= 10^2000) - the number of Chinese girls taking part in the game.

output
Output the only number - K that they should choose.

Sample Input

2

7

6

Sample Output
3

1

题意:给你一个n,n个数围城一圈,从数字1开始跳k,要求n个数都必须跳到,而且最后跳到1结束。
题解:找规律,多写几个数,发现当n是奇数的时候,k=n/2;当k是偶数的时候,如果k能对4取余等于0,k=n/2-1 ,否则k=n/2-2 .
因为数据太大,接下来需要模拟运算了。
直接上代码。
AC代码:

#include
#include
using namespace std;
int main()
{
	 int a[2005],b[2005];
	 int t;
	 string s;
	 cin>>t;
	 while(t--)
	 {
		  cin>>s;
		  memset(a,0,sizeof(a));
		  memset(b,0,sizeof(b));
		  int len=s.length();
		  for(int i=0;i=0;i--)
			   {
			    if(b[i]==0)
			    {
				     flag1=1;
				     continue;
			     } 
			    else
			    {
			     int k=i;
			     for(int j=k;j=2)
			   {
				    flag2=1;
				    b[len-1]-=2;
			   }
			   else
			   {
				    for(int i=len-2;i>=0;i--)
				    {
				     if(b[i]==0)
				      continue;
				     else
				     {
					      int k=i;
					      for(int i=k;i

你可能感兴趣的:(大数运算)