1023. Buttons

http://acm.timus.ru/problem.aspx?space=1&num=1023

简单博弈

代码:

import java.util.*;

import java.math.*;



public class Main {



	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		int n;

		while (in.hasNext()) {

			n=in.nextInt();

			int ans=n;

			for(int i=1;i<=Math.sqrt(n);++i){

				if(n%i==0){

					if(i-1>=2){

						ans=Math.min(ans ,i-1 );

					}

					if(n/i-1>=2){

						ans=Math.min(ans, n/i-1);

					}

				}

			}

			if(ans==n){

				ans=0;

			}

			System.out.println(ans);

		}

	}



}

 

你可能感兴趣的:(button)