CodeForces - 527 A Playing with Paper (模拟)

题目链接: 点击打开链接
题意:给一个长方形(也许是正方形)的长和宽,问能分出多少个正方形。

题解:模拟一下就能过,但是用减法会时间超限,需要用除法。

#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
	long long a,b;
	scanf("%lld%lld",&a,&b);
	if(a < b ){
		swap(a,b);
	}
	long long s = 0;
	while(a%b){
		s+= a/b;
		long long m = max(b,a%b);
		long long n = min(b,a%b);
		a = m;
		b = n;
	}
	printf("%lld\n",s+a/b);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/pk__pk/article/details/80449342
今日推荐