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( ...
随机推荐
- gridview自定义排序
效果如图: 首先允许排序:AllowSorting="True":开启gridview的排序事件onsorting="GridView1_Sorting",也可 ...
- putty ssh连接老断
有两种方法来解决:一. 配置客户端 1 在 linux下的ssh命令:vim /etc/ssh/ssh_config 然后找到里面的ServerAliveInterval 参数,如果没有你同样自己加一 ...
- Unity Standard Assets 简介之 Utility
决定写这个系列起因于刚才的偶然所见,我发现当前版本的Unity有一个 Utility 标准资源包,里面有一个 FPSCounter 脚本提供了显示游戏运行帧率的基本功能,而我几周前刚刚写过一个同样功能 ...
- BZOJ4504 : K个串
从左往右枚举右端点,用一棵线段树维护每个左端点的去重后的区间和. 那么对于$a[r]$,需要在$[pre[a[r]]+1,r]$里区间加上$a[r]$. 将线段树可持久化,并维护区间最大值,就可以在线 ...
- BZOJ4367 : [IOI2014]holiday假期
设 $fl[i]$表示从$S$向左走,用了不超过$i$天且不回头的最大收益. $fr[i]$表示从$S$向右走,用了不超过$i$天且不回头的最大收益. $gl[i]$表示从$S$向左走,用了不超过$i ...
- Window.location
1.location 对象 // 假设当前url是 http://localhost/rpc/plugin.php#hash?a=aaa&b=bbb alert(window.location ...
- Android AIDL 进行进程间通讯(IPC)
编写AIDL文件时,需要注意: 1.接口名和aidl文件名相同. 2.接口和方法前不用加访问权限修饰符 (public.private.protected等,也不能用final.static). 3. ...
- ACM Registration system
Registration system 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 A new e-mail service "Berlandesk&q ...
- ACM: HDU 2563 统计问题-DFS+打表
HDU 2563 统计问题 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u HDU 2 ...
- Codeforces Beta Round #3
A题,水题,还是无法1Y. B题,题意是类似背包的问题,在v的容量下,有1重量和2重量的,如果达到价值最大. 贪心,写的很恶心.看着数据过了. 奇数的时候,先选一个1.之后然后1+1 和 2 比较就行 ...