题意:就是一个蛋糕,被分成n或者m份。问最少动几刀。
看一下这个图,就知道公式了,n+m-gcd(n, m);
#include<cstdio> #include<iostream> using namespace std; #define ll long long ll gcd(ll a, ll b){ return b == 0 ? a : gcd(b, a%b); } int main() { ll n, m; while (scanf("%lld%lld", &n, &m) != EOF) { if (n < m){ swap(n, m); } printf("%lld\n", m + n - gcd(n, m)); } }
标签:HDU,gcd,ll,1722,long,Cake,include From: https://www.cnblogs.com/ALINGMAOMAO/p/17117654.html