题目:一开始,板上写有两个不相等的正整数.两个玩家交替写数字,每一次,当前玩家都必须在板上写出任意两个板上数字的差,而且这个数字必须是新的(且为正),也就是说,不能与板上任何一个已有的数字相同.当玩家再也写不出新数字时,他就输了.请问,你是选择先行动还是后行动呢?
1 import java.util.Scanner; 2 3 /** 4 * Created by Administrator on 14-7-16. 5 */ 6 public class EuclidGame { 7 public static void main(String[] args){ 8 int number=0; 9 System.out.println("please give the number:"); 10 Scanner scanner=new Scanner(System.in); 11 String str=scanner.nextLine(); 12 int a=Integer.parseInt(str); 13 str=scanner.nextLine(); 14 int b=Integer.parseInt(str); 15 winGame(gcd(a>b?a:b,a<=b?a:b),a>b?a:b); 16 } 17 public static int gcd(int a,int b){ 18 int r; 19 while(b!=0){ 20 r=a; 21 a=b; 22 b=r%a; 23 } 24 return a; 25 } 26 public static void winGame(int number,int max){ 27 if((max/number)%2!=0){ 28 System.out.println("the first one wins!"); 29 } 30 else { 31 System.out.println("the second one wins"); 32 } 33 } 34 }