UVALive 7045 Last Defence(找规律)

来源:互联网 发布:新手怎么做淘宝客 编辑:程序博客网 时间:2024/05/17 03:36

思路:找一下规律,就是一个类似辗转相除法的东西...


#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace std;typedef long long ll;ll a, b;ll get(ll A, ll B){if(B==0) return 1;ll t = A%B, ans=0;ans = A/B + get(B, t);return ans;}int main(){    //freopen("in.txt","r",stdin);    //freopen("out.txt","w",stdout);int ca=1,tt;scanf("%d", &tt);while(ca<=tt){scanf("%lld%lld", &a, &b);if(b>a) swap(a, b);if(a!=0&&b==0) printf("Case #%d: %lld\n", ca++, 2);else printf("Case #%d: %lld\n", ca++, get(a, b));}    return 0;}


0 0
原创粉丝点击