LightOj 1215 - Finding LCM(求LCM(x, y)=L中的 y )
题目链接: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
*/
LightOj 1215 - Finding LCM(求LCM(x, y)=L中的 y )的更多相关文章
- LightOj 1215 Finding LCM
Discription LCM is an abbreviation used for Least Common Multiple in Mathematics. We say LCM (a, b, ...
- apt-get -y install中的-y是什么意思?
是同意的意思.没有 -y的命令也可以执行,系统会提示你是否安装,输入y,回车,就会安装了 apt-get -y install这个指令则是跳过系统提示,直接安装.
- lightoj 1215
lightoj 1215 Finding LCM 链接:http://www.lightoj.com/volume_showproblem.php?problem=1215 题意:已知 a, b, l ...
- Finding LCM LightOJ - 1215 (水题)
这题和这题一样......只不过多了个数... Finding LCM LightOJ - 1215 https://www.cnblogs.com/WTSRUVF/p/9316412.html #i ...
- 1215 - Finding LCM
1215 - Finding LCM LCM is an abbreviation used for Least Common Multiple in Mathematics. We say LC ...
- BZOJ4833: [Lydsy1704月赛]最小公倍佩尔数(min-max容斥&莫比乌斯反演)(线性多项式多个数求LCM)
4833: [Lydsy1704月赛]最小公倍佩尔数 Time Limit: 8 Sec Memory Limit: 128 MBSubmit: 240 Solved: 118[Submit][S ...
- POJ-2429 GCD & LCM Inverse---给出gcd和lcm求原来两个数
题目链接: https://cn.vjudge.net/problem/POJ-2429 题目大意: 给出两个数的gcd和lcm,求原来的这两个数(限定两数之和最小). 解题思路: 首先,知道gcd和 ...
- Solve Equation gcd(x,y)=gcd(x+y,lcm(x,y)) gcd(x,y)=1 => gcd(x*y,x+y)=1
/** 题目:Solve Equation 链接:http://acm.hnust.edu.cn/JudgeOnline/problem.php?id=1643 //最终来源neu oj 2014新生 ...
- ATcoder E - Flatten 质因子分解求LCM
题解:其实就是求n个数的lcm,由于数据特别大,求lcm时只能用质因子分解的方法来求. 质因子分解求lcm.对n个数每个数都进行质因子分解,然后用一个数组记录某个质因子出现的最大次数.然后累乘pow( ...
随机推荐
- sqlSQL2008如何创建定时作业
SQL2008如何创建定时作业?此方法也适应于Sql Server2005数据库,有兴趣的可以来看下! 1.打开[SQL Server Management Studio],在[对象资源管理器]列表中 ...
- ural 2071. Juice Cocktails
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...
- 【Excel】Excel根据单元格背景色求和
例:用公式计算单元格背景色为浅蓝色的数字之和 步骤一: Office 2003 Insert->Name->Define,Names in workbook输入getColor或ge ...
- connect & express简介
Node.js[5] connect & express简介 Node.js[4] 第一个模块 Node.js[3] 俯瞰API (整理中) Node.js[2] Hello Node Nod ...
- 201453408刘昊阳 《Java程序设计》第5周学习总结
201453408刘昊阳 <Java程序设计>第5周学习总结 教材学习内容总结 第8章 异常处理 8.1 语法与继承结构 8.1.1 使用try.catch p227代码(Average) ...
- Windows 8 Tips
Precisely this article is about Windows 8.1, the title uses Windows 8 due to the fact that Windows 8 ...
- ACM 房间安排
房间安排 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 2010年上海世界博览会(Expo2010),是第41届世界博览会.于2010年5月1日至10月31日期间, ...
- 关于jQuery的inArray 方法介绍
例如: 代码如下: $.get('aaaaa.ashx',null,function(d){ // 假设d 返回 的值为 1,3,43,23,54,67 var arr = d.split(','); ...
- 【BZOJ】3834: [Poi2014]Solar Panels
http://www.lydsy.com/JudgeOnline/problem.php?id=3834 题意:求$max\{(i,j)\}, smin<=i<=smax, wmin< ...
- 如何将一个对象存到网页中并在js中使用
需求:希望在js中使用Controller传过来的对象,特别是对象里存有list的数据. 不希望循环使用隐藏域. 解决办法:在View中使用Json.Net序列化: @{ string jsonStr ...