没用运用好式子。。。想想其实很简单,首先应该分析,由于每次加一个LCM是大于等于其中任何一个数的,那么我LCM加在哪个数上面,那个数就是会变成大的,这样想,我们就知道,每个(x,y)对应就一种情况。

第二个突破口是,那个式子,我们可以想一想,是不是可以把数进行拆分,我们发现

a=x*k,b=y*k;其中k=gcd(a,b) 并且 x和y互质,这样带入式子,这样我们就把(x*k,y*k)推到了(x*k,x*y+x*y*k),化简即k *(x,(x+1)*y),gcd仍然是k,反过来,我们只需要保证,前一步,大的值满足(b>a)  b%(a+1)==0 并且 gcd(a,b)=K。不断迭代过程即可

#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
using namespace std;
int cnt;
int gcd(int x,int y){
return x%y==?y:gcd(y,x%y);
}
void solve(int x,int y){
if (x>y){
swap(x,y);
}
if (y%(x+)){
return ;
}else {
cnt++;
solve(x,y/(x+));
} }
int main(){
int t;
int ex,ey;
scanf("%d",&t);
int z=;
while(t--){
z++;
cnt=;
scanf("%d%d",&ex,&ey);
int x=max(ex,ey);
int y=min(ex,ey);
int k=gcd(ex,ey);
x/=k;y/=k;
solve(x,y);
printf("Case #%d: %d\n",z,cnt);
}
return ;
}

hdu 5584 LCM Walk的更多相关文章

  1. HDU 5584 LCM Walk 数学

    LCM Walk Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5584 ...

  2. HDU 5584 LCM Walk(数学题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5584 题意:(x, y)经过一次操作可以变成(x+z, y)或(x, y+z)现在给你个点(ex, e ...

  3. HDU 5584 LCM Walk【搜索】

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5584 题意: 分析: 这题比赛的时候卡了很久,一直在用数论的方法解决. 其实从终点往前推就可以发现, ...

  4. hdu 5584 LCM Walk(数学推导公式,规律)

    Problem Description A frog has just learned some number theory, and can't wait to show his ability t ...

  5. HDU - 5584 LCM Walk (数论 GCD)

    A frog has just learned some number theory, and can't wait to show his ability to his girlfriend. No ...

  6. HDU 5844 LCM Walk(数学逆推)

    http://acm.hdu.edu.cn/showproblem.php?pid=5584 题意: 现在有坐标(x,y),设它们的最小公倍数为k,接下来可以移动到(x+k,y)或者(x,y+k).现 ...

  7. L - LCM Walk HDU - 5584 (数论)

    题目链接: L - LCM Walk HDU - 5584 题目大意:首先是T组测试样例,然后给你x和y,这个指的是终点.然后问你有多少个起点能走到这个x和y.每一次走的规则是(m1,m2)到(m1+ ...

  8. HDU5584 LCM Walk 数论

    LCM Walk Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  9. hdu-5584 LCM Walk(数论)

    题目链接:LCM Walk Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)To ...

随机推荐

  1. [20181214]open file using O_DIRECT.txt

    [20181214]open file using O_DIRECT.txt --//因为一个测试需要,需要写一个测试小例子,验证使用O_DIRECT打开文件每次都是从磁盘读取.--//没想到浪费1个 ...

  2. define和typedef的区别

    define和typedef的区别 define是单纯的字符替换,typedef是重新定义了新的类型 #include <stdio.h> #define CHAR1 char* type ...

  3. Windows Server 2016-Windows Server Backup功能

    一.Windows Server Backup 介绍: Windows Server Backup 是一种功能,它提供了一组向导和其他工具,大概从WinSer2008开始Win Ser Backup引 ...

  4. python 制作一对一聊天

    用到的参考资料 https://blog.csdn.net/jia666666/article/details/81624550 https://blog.csdn.net/jia666666/art ...

  5. Windows 系统下 mysql workbench 的安装及环境配置

    1.MySQL的官网地址:https://www.mysql.com/ 2,选择DOWNLOADS 3.选择community 再MySQL workbench 4.安装MySQL workbench ...

  6. SSH 和 Git

    了解SSH SSH 以非对称加密实现身份验证.较常用的非对称加密有 RSA. 两种加密过程: 1.通过用户名密码访问服务器,即使传输的数据是加密的也可能会被劫持到不信任的服务器,泄露用户名和密码. 2 ...

  7. kafka-connect-hdfs连接hadoop hdfs时候,竟然是单点的,太可怕了。。。果断改成HA

    2017-08-16 11:57:28,237 WARN [org.apache.hadoop.hdfs.LeaseRenewer][458] - <Failed to renew lease ...

  8. HBase1.0.1.1 API与原来有所不同

    package com.felix.hbaseapi_test; /* 这是旧版的 API操作 */ public class hbaseapifelix { public static final ...

  9. 从n个数里面选择m个数

    从n个数里面选择m个数 #include<iostream> #include<vector> using namespace std; vector<int> s ...

  10. 解决Zabbix网页端Get value error: cannot connect to [[192.168.238.139]:10050]: [113] No route to host问题

    在安装配置完zabbix_agentd以后,网页端出现  Get value error: cannot connect to [[192.168.238.139]:10050]: [113] No ...