Split

/*Xiao Ming has some rectangular materials, and he wants to cut some squares from these rectangular materials.
When he is faced with a piece of rectangular material, he always makes a cut in the middle, cuts out the largest square, leaves a
piece of rectangle, and then cuts the remaining rectangular material until all squares are cut. For example, for a piece of material with 5 and 3 on both sides (denoted as 5×3),
Xiaoming will cut out 4 squares of 3×3, 2×2, 1×1, and 1×1 in turn.
 Now Xiao Ming has a rectangular piece of material, the lengths of which are 2019 and 324 on both sides. How many squares will Xiao Ming cut out in the end?
 * 
 */
public class Demo10 { public static void main(String[] args) {

	int i=2019;
	int j=324;
	a(i,j);
	System.out.println(a(i,j));
	}
	public static int a(int n,int m) {
		
		int sum=1;
		while (n!=m) {
			if(n>m){
				n=n-m;
				sum++;	
			}				
			else if(m>n){
				m=m-n;
				sum++;				
			}				
		}		
		return sum;
		
		
	}

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325318158&siteId=291194637