最小公倍数与最大公约数模板
2016-07-24 16:12
134 查看
#include <cstdio>
__int64 GCD(__int64 a,__int64 b)
{
if (a % b == 0)
return b;
else
return GCD(b,a%b);
}
__int64 LCM(__int64 a,__int64 b) // a * b / GCD(a,b)
{
return a / GCD(a,b) * b ;
}
int main()
{
__int64 a,b;
__int64 ans;
while (~scanf ("%I64d %I64d",&a,&b))
{
ans = LCM(a,b);
printf ("%I64d\n",ans);
}
return 0;
}
__int64 GCD(__int64 a,__int64 b)
{
if (a % b == 0)
return b;
else
return GCD(b,a%b);
}
__int64 LCM(__int64 a,__int64 b) // a * b / GCD(a,b)
{
return a / GCD(a,b) * b ;
}
int main()
{
__int64 a,b;
__int64 ans;
while (~scanf ("%I64d %I64d",&a,&b))
{
ans = LCM(a,b);
printf ("%I64d\n",ans);
}
return 0;
}
相关文章推荐
- HttpContext.Current.Cache 与HttpRuntime.Cache的区别
- bash命令行快捷键
- 一个产品菜鸟的起飞之路
- 装出现epel-release >= 6 is needed by remi-release-6.5-1.el6.remi.noarch 解决办法
- LeetCode 326. Power of Three
- 阿里面经之解答 by cmershen(5)——内存泄露,java.util.concurrent包
- 外键约束
- hrbust 1469 Wrong Answer【最大独立集---二分匹配】
- leetcode - Reverse Linked List
- [置顶] 分享一个好东西(一天精通MongoDB数据库)
- Python学习资料推荐
- jQuery选择器
- ButterKnife插件使用
- 分享一个好东西(一天精通MongoDB数据库)
- 龙芯小本debian无线(wifi)连接设置
- Github,乱码问题
- 插入排序
- 字符串专题
- View的滑动冲突解决方案
- AJAX编程模板