描述
题目描述:
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.
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 file contains multiple cases. Each case contains one integer number N (3 ≤ N ≤ 102000) - the number of Chinese girls taking part in the game.
输出:
Output the only number - K that they should choose for each input.
样例输入
7 6
样例输出
3 1
import java.math.BigInteger;
import java.util.Scanner;
public class ChineseGrils3 {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
BigInteger one=new BigInteger("1");
BigInteger two=new BigInteger("2");
while(in.hasNextLine()) {
BigInteger a=new BigInteger(in.nextLine());
if(a.mod(two).equals(one)) System.out.println(a.subtract(one).divide(two));
else {
BigInteger n=a.divide(two).subtract(one);
if(n.mod(two).equals(one)) System.out.println(n);
else System.out.println(a.divide(two).subtract(two));
}
}
}
}