题目链接

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5057

题意

给出两个数

递推式是 |s[i - 1] - s[i - 2]|

然后求这个数列 出现的不同数字的个数

思路

因为 X 和 Y 是整数

那么 我们可以理解为

Y = aX + b

也就是说 会是这样一个数列

(aX + b) (x) ((a - 1) X + b) ((a - 2)X + b) x b

然后 我们发现 最后的 x b

是一个递归的子问题

可以把 x b 看成新的 x y

递归下去

我们发现出口 实际上是 b == 0 的时候

然后对于每一次的迭代 答案都是 (kx + b) / x 也就是 k

当 b 等于0 的时候 迭代结束 答案要加上1 以为最后的0 是没有加上的

然后注意一下 当 给出的初始数字 存在0的时候 要讨论一下

AC代码

#pragma comment(linker, "/STACK:102400000,102400000")

#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <list>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits> #define CLR(a, b) memset(a, (b), sizeof(a));
#define pb push_back
#define bug puts("***bug***");
#define fi first
#define se second
#define L(on) (on<<1)
#define R(on) (L(on) | 1)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define syn_close ios::sync_with_stdio(false); cin.tie(0);
#define sp system("pause");
#define gets gets_s using namespace std; typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <string, int> psi;
typedef pair <string, string> pss;
typedef pair <double, int> pdi; const double PI = acos(-1.0);
const double EI = exp(1.0);
const double eps = 1e-8; const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fll;
const int maxn = (int)1e5 + 10;
const ll MOD = (ll)1000000000; int main()
{
int t; cin >> t;
for (int tt = 1; tt <= t; tt++)
{
printf("Case #%d: ", tt);
ll n, m; scanf("%lld%lld", &n, &m);
if (n == 0 || m == 0)
printf("%d\n", n == m ? 1 : 2);
else
{
ll ans = 1;
if (n < m) swap(n, m);
while (m)
{
ans += n / m;
ll tmp = m;
m = n % m;
n = tmp;
}
printf("%lld\n", ans);
}
}
}

UVALive - 7045 Last Defence 【数学】的更多相关文章

  1. UVALive 7045 Last Defence

    ProblemK. Last Defence Description Given two integersA and B. Sequence S is defined as follow: • S0 ...

  2. UVALive 5058 Counting BST 数学

    B - Counting BST Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit S ...

  3. UVaLive 7500 Boxes and Balls (数学)

    题意:给定 n 个球,每次从每篮子里拿出来一个放在一个新篮子里,并移除相同的,按球的个数进行排序,问你用最多几个球能完成循环. 析:数学问题,很容易发现前n项和就是最多的球数,所以我们只要找最大的n项 ...

  4. UVALive 7147 World Cup(数学+贪心)(2014 Asia Shanghai Regional Contest)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...

  5. UVaLive 6628 Grachten (水题,数学)

    题意:给定一个平面图形并且且给了几条连,求一条. 析:简单么,三角形相似,很简单就AC. 代码如下: #pragma comment(linker, "/STACK:1024000000,1 ...

  6. UVaLive 6862 Triples (数学+分类讨论)

    题意:给定一个n和m,问你x^j + y^j = z^j 的数量有多少个,其中0 <= x <= y <= z <= m, j = 2, 3, 4, ... n. 析:是一个数 ...

  7. UVaLive 7362 Farey (数学,欧拉函数)

    题意:给定一个数 n,问你0<= a <=n, 0 <= b <= n,有多少个不同的最简分数. 析:这是一个欧拉函数题,由于当时背不过模板,又不让看书,我就暴力了一下,竟然A ...

  8. UVaLive 7359 Sum Kind Of Problem (数学,水题)

    题意:给定一个n,求前 n 个正整数,正奇数,正偶数之和. 析:没什么好说的,用前 n 项和公式即可. 代码如下: #pragma comment(linker, "/STACK:10240 ...

  9. Gym 101194E / UVALive 7901 - Ice Cream Tower - [数学+long double][2016 EC-Final Problem E]

    题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...

随机推荐

  1. 【转】Intellij IDEA常用配置详解

    1. IDEA内存优化 先看看你机器本身的配置而配置. \IntelliJ IDEA 8\bin\idea.exe.vmoptions -------------------------------- ...

  2. java代理ip有效检测

    java实现代理ip有效检测,依赖Apache的HttpClient   正式版:       /**        * 批量代理IP有效检测        *        * @param pro ...

  3. bios文字解释

    很多笔记本电脑用户由于不熟悉bios,导致在需要设置bios时不知如何下手,其实bios基本大同小异,熟悉了以后再遇到bios设置就手到擒来了. 今天我们以笔记本电脑为例,进行bios界面的解读. 1 ...

  4. Cookie-Parser是怎样解析签名后的cookie的(同一时候对cookie和cookie-signature进行说明)

    第一步:我们来学习一下cookie-signature: var cookie=require('./index'); var val = cookie.sign('hello', 'tobiisco ...

  5. vim命令行模式

    1. 激活命令行模式 : 进入命令行模式 <Esc>  退出命令行模式 2. 常用命令 :p 打印 (:print) :e 读入文件 (:edit) :w 写入文件 (:write) :t ...

  6. angularjs中的$q

    先说说什么是Promise,什么是$q吧.Promise是一种异步处理模式,有很多的实现方式,比如著名的Kris Kwal's Q还有JQuery的Deffered. 什么是Promise 以前了解过 ...

  7. objective-C中的扩展方法与partial class

     在c#中要扩展一个现有类非常easy,比方这样: ? 1 2 3 4 5 6 7 public static class Utils {     public static void PrintTo ...

  8. java锁之wait,notify(wait会释放锁,notify仅仅只是通知,不释放锁)

    wait是指在一个已经进入了同步锁的线程内,让自己暂时让出同步锁,以便其他正在等待此锁的线程可以得到同步锁并运行,只有其他线程调用了notify方法(notify并不释放锁,只是告诉调用过wait方法 ...

  9. nodejs eclipse

    nodejs下载地址 http://nodejs.org/1.下载并安装完nodejs后,打开cmd命令窗口,输入node -v,如果正确输出版本号,就是安装成功了,如果说node不是windows的 ...

  10. Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '' for column 'createtime' at row 1...

    之前项目一直好好的,之后电脑重装系统,数据库重新安装了一个5.6版本的,项目jar包丢失了,之后就又重新找了一些jar包倒入,结果运行报错: Caused by: com.mysql.jdbc.Mys ...