LightOj 1215 - Finding LCM(求LCM(x, y)=L中的 y )
2024-10-11 23:04:43
题目链接:http://lightoj.com/volume_showproblem.php?problem=1215
题意:已知三个数a b c 的最小公倍数是 L ,现在告诉你 a b L 求最小的 c ;
其实就是告诉你(最小公倍数LCM)LCM(x, y) = L 已知 x 和 L 求 最小的 y ;
L = LCM(x, y)=x*y/gcd(x, y);如果把x,y,L写成素因子之积的方式会很容易发现 L 就是 x 和 y 中素因子指数较大的那些数之积;
例如LCM(24, y) = 480,y最小为160
24 = 2^3 * 3 ;
480 = 2^5 * 3 * 5 ;
那么一个数的因子中一定含有 5 ,要最小,一定不含3,还有就是一定有2,因为是24*num/gcd(24, num),所以有2^5才能满足
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<vector>
using namespace std;
typedef long long LL;
const int oo = 0xfffffff;
const int N = ; LL gcd(LL a, LL b)
{
return b==?a:gcd(b, a%b);
} int main()
{
int T, t = ; scanf("%d", &T); while(T--)
{
LL a, b, L; scanf("%lld %lld %lld", &a, &b, &L); printf("Case %d: ", t++); LL x = a*b/gcd(a, b); if(L%x) puts("impossible");
else
{
LL y = L/x, r; /// x * y = L;逐步扩大 y,缩小 x; while(r = gcd(x, y), r!=)
{
x /= r;
y *= r;
}
printf("%lld\n", y);
}
}
return ;
}
/*
4 6 24
6 8 480
8
160
*/
最新文章
- ERROR [IM002] [Microsoft][ODBC 驱动程序管理器] 未发现数据源名
- 计算机启动boot
- C#字符串处理(String与StringBuilder)
- Oracle Form Data Entry Sample
- 关于Strut2内置Json插件的使用
- UVa11324 The Largest Clique(强连通分量+缩点+记忆化搜索)
- oracle的to_number、to_char、to_date用法
- IIs工作原理
- Java多线程练习二
- win7使用右键导致死机、假死、explorer无法响应的解决方法
- STL内存管理器的分配策略
- [转]解决get方法传递URL参数中文乱码问题
- iOS超全开源框架、项目和学习资料汇总 UI篇
- 关于MySQL&#160;5.6.24&#160;解压缩版重启电脑后,无法启动的问题
- Django+Vue打造购物网站(十一)
- kubernetes in action - Pods
- (转)C# System.Diagnostics.Process.Start使用
- array的方法 没记住的
- 教程:如何手动安装Xamarin与Xamarin for VisualStudio
- UOJ#414. 【APIO2018】新家
热门文章
- Sqlserver自定义函数Function
- Hadoop Streaming框架使用(一)
- Mysql如何修改unique key
- 【BZOJ】1532: [POI2005]Kos-Dicing
- Centos 开放80端口
- 分享一个在线生成站点地图SiteMap制作工具
- maven创建web工程,并导入到eclipse中
- [LintCode] Shape Factory 形状工厂
- springMVC+spring+hibernate注解上传文件到数据库,下载,多文件上传
- CSS,bootstrap表格控制当td内容过长时用省略号表示,以及在不使用bootstrap时过长也用省略号表示