HDU 5640 King's Cake Posted on 2016-03-14 | In ACM | | Visitors 题目链接HDU 5640小模拟,递归求解 题目分析题目大意BestCoder #75a 中文题面 解析递归求解即可。 代码1234567891011121314151617181920212223242526272829303132333435363738394041424344454647#include <set>#include <map>#include <stack>#include <cmath>#include <queue>#include <cstdio>#include <string>#include <vector>#include <iomanip>#include <cstring>#include <iostream>#include <algorithm>#define Memset(a,val) memset(a,val,sizeof(a))#define PI acos(-1)#define rt(n) (i == n ? '\n' : ' ')#define hi printf("Hi----------\n")#define debug(x) cout<<"Debug : ---"<<x<<"---"<<endl;#define eps 1e-8#define INF 0x3f3f3f3f#pragma comment(linker, "/STACK:1024000000,1024000000")typedef long long ll;using namespace std;#define maxn 100000+5#define mod 1000000007int work(int n,int m){ if (n==0||m==0) { return 0; } if (n==m) { return 1; } else{ if (m>n) { swap(n, m); } return n/m+work(m, n%m); }}int main(){ int t; int n,m; cin>>t; while (t--) { cin>>n>>m; cout<<work(n,m)<<endl; }}